-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Fix for #6300 - I18n float validator rewrite #6373
Fix for #6300 - I18n float validator rewrite #6373
Conversation
…bers, exponential notation, and a few "look-alike" characters (space for NO_BREAK SPACE, comma for ARABIC DECIMAL SEPARATOR, and single quote for ARABIC THOUSANDS SEPARATOR).
…rmatters; Move to prefix/suffix logic due to locales like mr; Remove LRM from string and symbols
…missing grouping sizes for some locales)
{ | ||
$valid = new FloatValidator(array('locale' => 'en_US')); | ||
$this->assertEquals($expected, $valid->isValid($float)); | ||
Locale::setDefault('de'); |
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.
Make sure to reset the locale to what it was before.
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 teardown()
for the class resets the locale to whatever it was coming in.
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.
Ah, nevermind then.
'(' . $suffix . '(' . $lnum . $prefix . $exp . '(' . $dnum . '|' . $lnum . '))' . $prefix . '))'; | ||
|
||
//LEFT-TO-RIGHT MARK (U+200E) is messing up everything for the handful of locales that have it | ||
$lnumSearch = str_replace("\xE2\x80\x8E", '', '/^' .$prefix . $lnum . $suffix . '$/'.$useUnicode); |
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.
Either use (
and )
as regex delimiters instead of /
, or add the /
as second parameter to all preg_quote()
calls.
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.
@DASPRiD umm... this is a str_replace
, not preg_quote
...
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.
@weierophinney @DASPRiD was referring to lines 169, 178, and 186. I added the slash as suggested. Not sure why his comment still shows. Github quirk.
Sadly we have disabled coveralls for pull requests because of the noise. Would you mind exporting a coverage report for the validator? I just want to make sure that this is properly covered. |
@DASPRiD gotta admit my ignorance here. What software were you looking for me to use for the coverage report? I can say I tested this with all the locales from ICU 53 and it passed. I know that's not what you meant, but just FYI for the reviewers. |
@moderndeveloperllc Just run |
{ | ||
$trueArray = array(); | ||
$testingLocales = array('ar', 'bn', 'de', 'dz', 'en', 'fr-CH', 'ja', 'ks', 'ml-IN', 'mr', 'my', 'ps', 'ru'); | ||
$testingExamples = array(1000, -2000, +398.00, 0.04, -0.5, .6, -.70, 8E10, -9.3456E-2, 10.23E6); |
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 have a few of suggestions that can be added to this test -
- High Precision float values such as 123.1234567890987654321
- Testing strings e.g. "123.1234567890987654321" (had a problem with this recently not passing the validator)
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.
@rahuldroy Eh, why not. Note: This will pass as decimal because we now only check that the input is in the form of a float and don't try and do any value equivalence checking like the old validator. The old validator was doing some processing of the number and then checking that the value did not change. This ran into the issue you saw - PHP and it's "lax" handling of floats that have a large number of significant digits.
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.
@moderndeveloperllc cool thanks 👍 . You are right about PHPs handling of floats and I believe that is something that needs to be addressed upstream urgently. I was rewriting that part myself (only to find out that you were already working on it)
…idator, but this validator correctly passes it for all locales.
@DASPRiD I put up the HTML at https://gist.github.com/moderndeveloperllc/3b63cd47dfd7c576e2bd#file-floatcoverage It seems to be rather well covered with the exception of a few of the standard exceptions . |
@DASPRiD is this PR ready to be merged? |
- Concatenators should be on following line - `||`/`&&` should be on following line - Spaces around `.` concatenation - Trailing whitespace
Cherry-picked to master for release with 2.3.2; merged to both master and develop. |
} | ||
|
||
if (strval($parsedFloat) !== $valueFiltered) { | ||
$this->error(self::NOT_FLOAT); |
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.
According to @NickBelhomme, this change is causing trouble, as this error message is not being displayed anymore when upgrading to 2.3.3 from any previous version.
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.
See #6647
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.
@Ocramius Did you mean to put this message on this PR? I know there are a few others out there talking about NOT_FLOAT. Personally, I never saw the utility of the error message as this is a validator - if the method returns false
the input is, by definition, not a float. I kept in the error messages that were caused my bad inputs or instantiations. But if y'all want to include errors like this, others are welcome to include them.
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.
@moderndeveloperllc it can be changed, but only as a BC break in a point release
- Concatenators should be on following line - `||`/`&&` should be on following line - Spaces around `.` concatenation - Trailing whitespace
Fix for #6300. This is a complete rewrite of the validator to account for non-latin number systems, scientific notation, and "look-alike" characters (space for NO-BREAK SPACE, comma for ARABIC DECIMAL SEPARATOR, and single quote for ARABIC THOUSANDS SEPARATOR). Though the test class only tests against 13 locales, the logic was tested against all 709 locales in CLDR 25.
This also includes a small cleanup of the formatting on NumberFormat filter and removal of the extraneous NO-BREAK SPACE removal.
Rewrite of the test class to use programmatic values for
true
tests using both decimal and scientific notation.