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

Strange currency code strings like X+|\u0019F allow to create a CurrencyUnit #428

Open
gerardbosch opened this issue Feb 5, 2025 · 0 comments

Comments

@gerardbosch
Copy link

gerardbosch commented Feb 5, 2025

I faced something strange when instantiating CurrencyUnit from the currencyCode string.

Some strings like "X*", "X+|" and others were allowed to create a currency.

Here is a small test to exemplify the situation and some comparison with java.util.Currency:

  @Test
  void monetaCurrencyUnit() {
    // SOME STRANGE STRINGS ARE ALLOWED! The test PASSED
    Monetary.getCurrency("X*");
    Monetary.getCurrency("X*|helloWorld");
    Monetary.getCurrency("X+|\u0019F\"CW:'NEvS�\u0017N\u000BL\u001B ~K\u0001");
  }

  @Test
  void monetaCurrencyUnitLowerHistorical() {
    // This fails as I was expecting, and that led me think that the Moneta impl of currency is more sound.
    // Because on the other hand, when using java.util.Currency, it works.
    Monetary.getCurrency("EUr");
  }

  @Test
  void jdkCurrency() {
    // Both throw exception as I would expect (not the case in Moneta `CurrencyUnit`: `Monetary.getCurrency()`)
    java.util.Currency.getInstance("X*");
    java.util.Currency.getInstance("X+|\u0019F\"CW:'NEvS�\u0017N\u000BL\u001B ~K\u0001");
  }

  @Test
  void jdkCurrencyLowerHistorical() {
    // I was not expecting this, but only some currencies work when the last char is lowercase like:
    java.util.Currency.getInstance("ESp"); // YUm ok, BEf ok, DEm ok, ADp ok (they're all historical currencies), EUr also works
  }
@gerardbosch gerardbosch changed the title Strange currency code strings like "X*" allow to create a CurrencyUnit Strange currency code strings like X+|\u0019F allow to create a CurrencyUnit Feb 5, 2025
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

1 participant