Repository navigation
Conversation
The parser only removed the currency symbol when it was the first thing
in the input (`^#{currency.symbol}`). Anywhere else the symbol fell to
the generic character filter, which keeps dots, so the dot of symbols
such as "Rs." or "kr." was read as a decimal mark:
Monetize.parse('-Rs.1,500', 'NPR') # => -1.50 NPR, expected -1,500.00
Monetize.parse('-kr.10', 'DKK') # => -0.10 DKK, expected -10.00
Monetize.parse('NPR Rs.10') # => 0.10 NPR, expected 10.00
Remove the symbol as a literal string wherever it appears before the
character filter runs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Monetize::Parser#parseremoves the currency symbol only when it is at the very start of the input (/^#{currency.symbol}/). When anything comes before it, such as a minus sign or the ISO code, the symbol is left to the generic[^\d.,'-]+filter. That filter keeps dots, so the dot in symbols likeRs.(NPR) orkr.(DKK, ISK) is read as the decimal mark:The same inputs without the leading
-or code already parse correctly ('kr.123,45'has a spec), and"-#{symbol}5.95"is covered by specs for every entry inCURRENCY_SYMBOLS, but none of those symbols contain a dot.Change: the symbol is now removed as a literal string wherever it appears, before the character filter runs (
remove_currency_symbol). Using a string ingsubalso stops the symbol from being read as a regular expression. Currencies with no symbol are left alone.I checked every currency in
Money::Currency.allwith"#{symbol}10","#{symbol} 10","10 #{symbol}","#{symbol}-10"and"-#{symbol}10": before the change 23 currencies (DKK, ISK, NPR, BGN, BOB, PAB, AED, SAR, MAD, OMR and others) gave a wrong value or an error for"-#{symbol}10". After the change all of them give 10 or -10.Added a spec in
spec/monetize_spec.rb(ignores the dot of a currency symbol that does not start the input) and a CHANGELOG line under Unreleased.Tests: I did not run the project's
bundle exec rspec spec. rspec and the money gem'si18ndependency were not installed where I worked, so I ran the two spec files with money 7 from source and a small stand-in for the RSpec DSL they use:spec/monetize_spec.rb328 examples, 1 failure (the new spec:-kr.10gave -0.10 DKK);spec/core_extensions_spec.rb25 examples, 0 failures