Skip to content

Version 1.11.0 broke parsing for Malaysian ringgit when using the symbol 'RM' #153

@goalaleo

Description

@goalaleo

Malaysian ringgit, ISO code: MYR, symbol: RM.
The commit that broke our code is this one which prioritises ISO code over a symbol. It makes the incorrect assumption that the first line only matches ISO codes:

computed_currency = input[/[A-Z]{2,3}/]
computed_currency ||= compute_currency if assume_from_symbol?

While it's true that the regexp doesn't match any symbols in CURRENCY_SYMBOLS, there are a few currencies where the symbol is 2-3 capital letters

Using version 1.9.4

Monetize::Parser::CURRENCY_SYMBOLS["RM"] = "MYR"
Monetize.parse("100 RM")
=> #<Money fractional:10000 currency:MYR>

In version 1.11.0, expected same result, got

=> nil

I propose that if

computed_currency = input[/[A-Z]{2,3}/]

returns a match, the code will check if CURRENCY_SYMBOLS contains it as a key before assuming that it's an ISO code.

As a side note: what is the recommended way of "registering" symbols that are not included in the gem? In our app we've added them to the Monetize::Parser::CURRENCY_SYMBOLS hash, but maybe this is not recommended?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions