Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Validation::decimal accept integers
Fix #2800 Force locale of ValidationTests with en_US to ensure decimal dot separator
- Loading branch information
1 parent
afbd582
commit 28bd688
Showing
2 changed files
with
11 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28bd688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is Validator::decimal() nos validation decimal point anymore?¿
Even the docs says it should:
From:
to
28bd688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well 1234 is a valid decimal value, as it has implicit 00's
28bd688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, but the whoie point of testing against decimal(), and not numeric() or naturalNumber() is to detect a decimal point (again, as the documentation says). It can't be right that (int)1234 passes the test...
28bd688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original issue that created this change was http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/2800 The wikipedia article on decimal values says
Which seems reasonable considering decimal values generally come from user input, and requiring trailing zero's seems a bit excessive. Both '10' and '10.000' have the same representation in both PHP and Javascript. Additionally databases like MySQL and SQLite treat these values as interchangeable as does Postgres from what I remember.
28bd688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because of PHP type juggling feature and being loosely typed, it removes trailing zeroes and automatically types the value to
float
, so when you type13.00
ends being(float) 13
, but when you type'13.00'
, it does not change but correctly passes the tests.The solution to that can be undoing what PHP does when a float number is detected, a working proof of concept with old tests and new ones should be:
bar@70deff6
28bd688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating the commit with a clearly invalid test wich fails here because of the
()?
regex groupingbar@a59548a
28bd688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with bar. I would only use the decimal validation rule if I wanted to validate a number with a decimal place: 10.23, 45323.33 and even 4343.00. Numbers without a decimal shouldn't pass IMO.
28bd688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bar a59548a5e951f433dc24e3040c708941ca37de50 seems like a reasonable change as '' passing as a decimal is wrong like you said.
28bd688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markstory yes, it seemed odd...
28bd688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the change @bar, merged in b75a6b4
28bd688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, being able to contribute to the core is always a pleasure!