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

Commit 6e20263

Browse files
author
Arthur LORENT
committed
1.1.3
2 parents 6968b9f + bb1608b commit 6e20263

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [1.1.3](https://github.com/Okipa/laravel-request-sanitizer/releases/tag/1.1.3)
4+
2019-09-13
5+
- Fixed wrong sanitizing for doubles.
6+
37
## [1.1.2](https://github.com/Okipa/laravel-request-sanitizer/releases/tag/1.1.2)
48
2019-09-12
59
- Fixed missing `string` return type in `sanitize()` and `sanitizeFromType()` methods PHPDOC.

src/DataSanitizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function sanitizeFromType($entry, bool $jsonDecodeAssoc)
5151
} elseif ($this->isTrue($entry)) {
5252
return true;
5353
} elseif (is_numeric($entry)) {
54-
if ((int) $entry !== $entry) {
54+
if (((int) $entry) - ((double) $entry) !== 0.0) {
5555
return doubleval($entry);
5656
} else {
5757
return intval($entry);

tests/DataSanitizerTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,24 @@ public function testSanitizeReturnsNullForEmptyString()
4444
$this->assertNull($this->DataSanitizer->sanitize(''));
4545
}
4646

47-
public function testSanitizeTransformsStringToNumber()
47+
public function testSanitizeInteger()
4848
{
49-
$this->assertEquals(0, $this->DataSanitizer->sanitize('0'));
50-
$this->assertEquals(2.07, $this->DataSanitizer->sanitize('2.07'));
49+
$this->assertEquals(3, $this->DataSanitizer->sanitize('3'));
50+
}
51+
52+
public function testSanitizeNegativeInteger()
53+
{
54+
$this->assertEquals(-3, $this->DataSanitizer->sanitize('-3'));
55+
}
56+
57+
public function testSanitizeFloat()
58+
{
59+
$this->assertEquals(3.14, $this->DataSanitizer->sanitize('3.14'));
60+
}
61+
62+
public function testSanitizeNegativeFloat()
63+
{
64+
$this->assertEquals(-3.14, $this->DataSanitizer->sanitize('-3.14'));
5165
}
5266

5367
public function testSanitizeAcceptsDefaultParameter()

0 commit comments

Comments
 (0)