Skip to content

Commit

Permalink
allow incorrect decimal / float formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
segy committed Dec 14, 2018
1 parent 41a16ec commit f195735
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Database/Type/DecimalType.php
Expand Up @@ -158,7 +158,12 @@ public function marshal($value)
return (float)$value;
}

return null;
// allow custom decimal format (@see https://github.com/cakephp/cakephp/issues/12800)
if (preg_match('/[^0-9,. ]/', $value)) {
return null;
}

return $value;
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/Database/Type/FloatType.php
Expand Up @@ -147,7 +147,12 @@ public function marshal($value)
return (float)$value;
}

return null;
// allow custom decimal format (@see https://github.com/cakephp/cakephp/issues/12800)
if (preg_match('/[^0-9,. ]/', $value)) {
return null;
}

return $value;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase/Database/Type/DecimalTypeTest.php
Expand Up @@ -167,6 +167,9 @@ public function testMarshal()
$result = $this->type->marshal('2.51');
$this->assertSame(2.51, $result);

$result = $this->type->marshal('1 230,73');
$this->assertSame('1 230,73', $result);

$result = $this->type->marshal('3.5 bears');
$this->assertNull($result);

Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase/Database/Type/FloatTypeTest.php
Expand Up @@ -156,6 +156,9 @@ public function testMarshal()
$result = $this->type->marshal('2.51');
$this->assertSame(2.51, $result);

$result = $this->type->marshal('1 230,73');
$this->assertSame('1 230,73', $result);

$result = $this->type->marshal('3.5 bears');
$this->assertNull($result);

Expand Down

0 comments on commit f195735

Please sign in to comment.