varunsrin / rusty_money

Money library for Rust
MIT License
86 stars 32 forks source link

Fix ISO alpha and numeric code definitions in Currency objects #34

Closed zacharra closed 4 years ago

zacharra commented 4 years ago

Hello, while using this library I noticed that the Currency::find() function is returning an error for the HUF currency (InvalidCurrency). Investigating further, I found that the issue lies in the definitions of the ISO alpha codes in the Currency objects in the iso.rs file.
Due to the way the lookup maps are populated in currency.rs (using the iso_alpha_code field as key) this also causes the function to return the wrong Currency object for HTG, since the values in the hash map get overridden due to the duplicate values.
The PR also contains a fix for a similar copy-paste bug regarding the numeric codes as well as some tests to ensure those kind of bugs are caught before being merged. I put them in the same file, if you don't mind.

varunsrin commented 4 years ago

Thank you, really appreciate the fix and PR.