Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from v-technologies/fix-document-clean-flaot-inf
Browse files Browse the repository at this point in the history
fix Document::_clean()
  • Loading branch information
RomainS committed May 23, 2016
2 parents 5a81444 + a60c88b commit 7a07b0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Simples/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ protected function _clean(& $data, array $options = array(), $path = array()) {
} else {
unset($data[$key]) ;
}
} elseif (is_numeric($value)) {
} elseif (is_numeric($value) && (float)$value !== INF) {
$data[$key] = (float) $value ;
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/Simples/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,17 @@ public function testClean() {
$res = $document->to('array', array('clean' => true, 'cast' => array('sub.string' => 'float'))) ;
$this->assertTrue($res['sub'][0]['string'] === 9.0);
}

public function testCleanFloatInf() {
// Test clean
$document = new Simples_Document(array(
'string' => '3E7210'
)) ;
$res = $document->to('array', array('clean' => true)) ;

$this->assertTrue($res['string'] === '3E7210');

$res = $document->to('json', array('clean' => true)) ;
$this->assertEquals($res, '{"string":"3E7210"}');
}
}

0 comments on commit 7a07b0e

Please sign in to comment.