Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Commit

Permalink
1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur LORENT committed Sep 13, 2019
2 parents 6968b9f + bb1608b commit 6e20263
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.1.3](https://github.com/Okipa/laravel-request-sanitizer/releases/tag/1.1.3)
2019-09-13
- Fixed wrong sanitizing for doubles.

## [1.1.2](https://github.com/Okipa/laravel-request-sanitizer/releases/tag/1.1.2)
2019-09-12
- Fixed missing `string` return type in `sanitize()` and `sanitizeFromType()` methods PHPDOC.
Expand Down
2 changes: 1 addition & 1 deletion src/DataSanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function sanitizeFromType($entry, bool $jsonDecodeAssoc)
} elseif ($this->isTrue($entry)) {
return true;
} elseif (is_numeric($entry)) {
if ((int) $entry !== $entry) {
if (((int) $entry) - ((double) $entry) !== 0.0) {
return doubleval($entry);
} else {
return intval($entry);
Expand Down
20 changes: 17 additions & 3 deletions tests/DataSanitizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,24 @@ public function testSanitizeReturnsNullForEmptyString()
$this->assertNull($this->DataSanitizer->sanitize(''));
}

public function testSanitizeTransformsStringToNumber()
public function testSanitizeInteger()
{
$this->assertEquals(0, $this->DataSanitizer->sanitize('0'));
$this->assertEquals(2.07, $this->DataSanitizer->sanitize('2.07'));
$this->assertEquals(3, $this->DataSanitizer->sanitize('3'));
}

public function testSanitizeNegativeInteger()
{
$this->assertEquals(-3, $this->DataSanitizer->sanitize('-3'));
}

public function testSanitizeFloat()
{
$this->assertEquals(3.14, $this->DataSanitizer->sanitize('3.14'));
}

public function testSanitizeNegativeFloat()
{
$this->assertEquals(-3.14, $this->DataSanitizer->sanitize('-3.14'));
}

public function testSanitizeAcceptsDefaultParameter()
Expand Down

0 comments on commit 6e20263

Please sign in to comment.