Skip to content

[Yaml] deprecate comma separators in floats #18785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2016
Merged

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented May 14, 2016

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #18178
License MIT
Doc PR

@@ -591,6 +591,7 @@ private static function evaluateScalar($scalar, $flags, $references = array())
case 0 === strpos($scalar, '!!binary '):
return self::evaluateBinaryScalar(substr($scalar, 9));
case preg_match('/^(-|\+)?[0-9][0-9,]*(\.[0-9_]+)?$/', $scalar):
@trigger_error('Using the comma as a group separator for floats is deprecated since version 3.2 and will be removed in 4.0.', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this regexp right, the deprecation error will be triggered for example for numbers like 123.45 but it shouldn't. We'd need to test explicitly the presence of the comma.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, the order of regexps should be changed, to match the standard regex first to handle the case of values matching the spec
This will require to duplicate the line return (float) str_replace(array(',', '_'), '', $scalar); instead of using a fallthrough, but this is not an issue.

Copy link
Member Author

@xabbuh xabbuh May 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These cases are already handled further up where we have the is_numeric() check (and we have tests covering that this is working).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @javiereguiluz said, this deprecation will be triggered with 123.45, which is not correct. IMO, the * should be replaced with a + to ensure that a , is indeed used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, the + won't be enough ; we need to test that [0-9]+,[0-9]*(?:\.[0-9_]+)? matches this I think (but I'm not too sure too)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Taluu but it's true what @xabbuh said: this is handled in the code above this case: and there are tests about this and they pass.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it should be triggered for 123.45_67 though (I think), as there are no cases for that above this case, and that is valid though. And I think a _ may have been forgotten in the part before the . actually.

IMO, we should do a strpos test to test that a , is indeed in the match, and then only trigger the deprecation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Taluu You are right. I opened #18858 which should fix this issue.

And I think a _ may have been forgotten in the part before the . actually.

I think it's okay the way it is. We only introduced the _ for 3.2 and I think people should not start mixing _ and , then. If they want to use _, they should just move away from , as well.

@javiereguiluz
Copy link
Member

👍

Status: reviewed

@fabpot
Copy link
Member

fabpot commented May 24, 2016

Thank you @xabbuh.

@fabpot fabpot merged commit 3f3623d into symfony:master May 24, 2016
fabpot added a commit that referenced this pull request May 24, 2016
This PR was merged into the 3.2-dev branch.

Discussion
----------

[Yaml] deprecate comma separators in floats

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #18178
| License       | MIT
| Doc PR        |

Commits
-------

3f3623d [Yaml] deprecate comma separators in floats
@xabbuh xabbuh deleted the issue-18178 branch May 24, 2016 10:35
@fabpot fabpot mentioned this pull request Oct 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants