Commit 3a4c2c2e authored by Drew Webber's avatar Drew Webber
Browse files

Issue #2830428 by telecjose, mcdruid, ansebul, Rajender Rajan, Fabianx: Fix...

Issue #2830428 by telecjose, mcdruid, ansebul, Rajender Rajan, Fabianx: Fix behaviour of entity_load when passed ids with a trailing dot
parent 910da1be
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -254,7 +254,10 @@ protected function cleanIds(&$ids) {
   * Callback for array_filter that removes non-integer IDs.
   */
  protected function filterId($id) {
    return is_numeric($id) && $id == (int) $id;
    // ctype_digit() is used here instead of a strict comparison as sometimes
    // the id is passed as a string containing '0' which may represent a bug
    // elsewhere but would fail with a strict comparison.
    return is_numeric($id) && $id == (int) $id && ctype_digit((string) $id);
  }

  /**
+12 −0
Original line number Diff line number Diff line
@@ -46,4 +46,16 @@ class EntityLoadTestCase extends DrupalWebTestCase {
    $this->assertIdentical($nodes_loaded[$node_2->nid], $all_nodes[$node_2->nid], 'Loaded node 2 is identical to cached node.');
    $this->assertIdentical($nodes_loaded[$node_3->nid], $all_nodes[$node_3->nid], 'Loaded node 3 is identical to cached node.');
  }

  public function testEntityLoadIds() {
    $this->drupalCreateNode(array('title' => 'Node 1'));
    $this->drupalCreateNode(array('title' => 'Node 2'));

    $nodes_loaded = entity_load('node', array('1', '2'));
    $this->assertEqual(count($nodes_loaded), 2);

    // Ensure that an id with a trailing decimal place is ignored.
    $nodes_loaded = entity_load('node', array('1.', '2'));
    $this->assertEqual(count($nodes_loaded), 1);
  }
}