Money paste follow-ups: separator hint and symbol drift test

Merged
BE
2mo ago
+136-4

Part of #3395 (follow-ups from #3300).

Problem

Pasting 1,234 into a EUR money field wrote 1234 instead of 1.234: without a hint, the paste parser reads a comma before exactly three digits as a thousands separator. Before #3300 the browser rejected that paste, so this could now be saved by an auto-submit form.

Changes

1. Currency separator hint

  • The money field now carries the selected currency's decimal separator (data-money-field-separator-value) and passes it to parseAmountPaste.
  • The hint only decides the one ambiguous shape: a single , or . followed by exactly three digits. Other pastes keep the current parsing, so $1,234.56 pasted into a EUR field is still 1234.56.
PasteEUR beforeEUR afterUSD
1,23412341.2341234
1.2341.23412341.234
$1,234.561234.561234.561234.56

3. Symbol-list drift test

  • test/architecture/currency_paste_symbols_test.rb fails when CURRENCY_SYMBOL in parse_amount_paste.js drifts from the letter-free symbols in config/currencies.yml.
  • It's a Minitest rather than an .mjs test because CI doesn't run test/javascript.

Question on part 2 (lettered markers)

I've left USD 500, kr 500, R$ 1.234,56 falling through to the browser. The reason is already documented at the top of parse_amount_paste.js. Would you prefer to keep it that way, or ship a server-provided marker list (possibly limited to the selected currency's own symbol and ISO code)? If the status quo is fine, this PR can close the issue.

Validation

  • node --test test/javascript (13 new cases for the separator hint)
  • bin/rails test: 10,331 runs, 0 failures
  • System tests for money-field flows (transactions, transfers, goals, loans, account activity)
  • bin/rubocop, erb_lint, npm run lint, bin/brakeman: clean
  • Manually pasted the EUR values above into the new transaction form.

Summary by CodeRabbit

  • Bug Fixes
    • Pasted amounts with a single separator followed by exactly three digits are interpreted using the selected currency’s decimal separator, helping avoid incorrect readings of ambiguous values.
    • Other pasted amounts, including values with repeated grouping separators or a different number of digits after the separator, continue to be interpreted independently of the currency setting. This preserves existing behavior for values whose separator usage is unambiguous.