Proposed fix for ZF2-569 validating float with trailing 0's (10.0, 10.10) #2388

Closed
wants to merge 5 commits into
from

Conversation

Projects
None yet
3 participants
@Lansoweb
Contributor

Lansoweb commented Sep 19, 2012

The actual validation fails with trailing zeros inside decimal part like 10.0 or 10.10. This happens because NumberFormatter->parse('10.0') returns 10 and not 10.0 and the valueFiltered remains '10.0'.

This proposed fix removes all trailing 0 (and ending . if any) from valueFiltered before comparison.

The problem is described in http://framework.zend.com/issues/browse/ZF2-569

Lansoweb added some commits Sep 19, 2012

@pdobrigkeit

This comment has been minimized.

Show comment Hide comment
@pdobrigkeit

pdobrigkeit Sep 19, 2012

Contributor

Very nice. I was playing around with the idea to do a

$valueFiltered = preg_replace('/[0]*$/', $valueFiltered);

But that gave trouble when the value was actually 0 and now it seems I don't have to think anymore ;)

Contributor

pdobrigkeit commented Sep 19, 2012

Very nice. I was playing around with the idea to do a

$valueFiltered = preg_replace('/[0]*$/', $valueFiltered);

But that gave trouble when the value was actually 0 and now it seems I don't have to think anymore ;)

weierophinney added a commit that referenced this pull request Sep 19, 2012

[ZF2-569][#2388] CS fixes
- trailing whitespace
- break conditional into multiple lines for readability
- whitespace around operators

weierophinney added a commit that referenced this pull request Sep 19, 2012

Merge branch 'hotfix/zf2-569' into develop
Forward port #2388

Conflicts:
	library/Zend/I18n/Validator/Float.php
	tests/ZendTest/I18n/Validator/FloatTest.php

@ghost ghost assigned weierophinney Sep 19, 2012

weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015

[ZF2-569][zendframework/zendframework#2388] CS fixes
- trailing whitespace
- break conditional into multiple lines for readability
- whitespace around operators

weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015

weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015

Merge branch 'hotfix/zf2-569' into develop
Forward port zendframework/zendframework#2388

Conflicts:
	library/Zend/I18n/Validator/Float.php
	tests/ZendTest/I18n/Validator/FloatTest.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment