RubyMoney / monetize

A library for converting various objects into `Money` objects.
MIT License
430 stars 107 forks source link

Parsing Euro with iso code and assume_from_symbol returns ZAR #132

Closed ricobl closed 4 years ago

ricobl commented 4 years ago

After the 1.9.3 release, parsing any iso code ending with an R returns currency as ZAR when assume_from_symbol is on as demonstrated here:

irb(main):001:0> require 'monetize'
=> true
irb(main):002:0> 'EUR -13.00'.to_money
=> #<Money fractional:-1300 currency:EUR>
irb(main):003:0> Monetize.assume_from_symbol = true
=> true
irb(main):004:0> 'EUR -13.00'.to_money
=> #<Money fractional:-1300 currency:ZAR>
irb(main):005:0>

https://github.com/RubyMoney/monetize/commit/8bfb079ef3664baee2d0fe62702d57e727b1c96f is the only code change in that release, so it has probably something to do with that regex. The last char on the iso code seems to be matching the symbol.

antstorm commented 4 years ago

@ricobl thanks for noticing! The regexp used to detect a symbol that is at the beginning of a string or just after a sign. We probably need to restrict it to fix the issue you found… I'll have a look shortly

ricobl commented 4 years ago

No worries @antstorm. Thanks for chasing this.

antstorm commented 4 years ago

@ricobl opened a PR to fix the issue ^, hope I'm not missing any weird use-cases

ricobl commented 4 years ago

@ricobl opened a PR to fix the issue ^, hope I'm not missing any weird use-cases

Looks good, I made a review there. Thanks @antstorm.

antstorm commented 4 years ago

The new version (1.9.4) should be out now. Thanks again for bringing this up 👍

ricobl commented 4 years ago

Awesome, thanks for the quick release.