Problem/Motivation

In NumberFieldTest::testNumberDecimalField you can find $this->assertRaw(round($value, 2) where $value is "-1234.5678. Now, round() creates a floating point value. assertRaw runsstrpos($this->drupalGetContent(), $raw).

http://php.net/strpos

If needle is not a string, it is converted to an integer and applied as the ordinal value of a character.

Opsie! Actually, strpos($haystack, round(-1234.5678, 2)) searches for the humble dot. (YES! We love PHP.) Check For kicks, try php -r 'var_dump(strpos(".", round(-1234.5678, 2)));' -- consequently, this test will pass for any page containing a dot.

Proposed resolution

Do not round the string. Easy!

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
NumberFieldTest.patch763 byteschx

Comments

chx’s picture

Issue summary: View changes
webchick’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

chx and I looked through git blame to figure out where this came from, since it seemed odd to go through that amount of shenanigans in order to just check a value. We found our way all the way back to the issue where this was originally committed #950134: Number module maxlength prevents saving negative decimal. The intent of that issue was to make sure that - and . are accounted for in the maxlength. Reading the rest of the test, the fix chx has done here is sufficient.

Marking RTBC.

chx’s picture

Issue summary: View changes
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 54c2834 and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.