Skip to content
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

phony_formatted not returning original String for non-digit only strings #163

Closed
aptituz opened this issue May 8, 2017 · 1 comment
Closed

Comments

@aptituz
Copy link

aptituz commented May 8, 2017

The documentation for phony_formatted states that: "When an error occurs during conversion it will return the original String." but this is not true.

Given the following example:

'acbdef'.phony_formatted

it returns nil, too, since in all non-digit characters are removed from the string (https://github.com/joost/phony_rails/blob/master/lib/phony_rails/string_extensions.rb#L29).

In practice, when one uses phony_formatted for the value of an input field, this leads to user input wrongly replaced with nothing. The obvious workaround is something like

value.phony_formatted || value

But I wonder if the method itself shouldn't be changed in a way that matches the documented behaviour. Especially since there is an option to be strict about values.

@joost
Copy link
Owner

joost commented Sep 5, 2018

This is intended behaviour. The documentation intends that if you pass a string variable this string is not changed.

@joost joost closed this as completed Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants