Money paste follow-ups: separator hint and symbol drift test
Merged
BE
2mo ago+136+136+012345678901234567890123456789-4-4-0123456789
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 toparseAmountPaste. - 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.56pasted into a EUR field is still1234.56.
| Paste | EUR before | EUR after | USD |
|---|---|---|---|
1,234 | 1234 | 1.234 | 1234 |
1.234 | 1.234 | 1234 | 1.234 |
$1,234.56 | 1234.56 | 1234.56 | 1234.56 |
3. Symbol-list drift test
test/architecture/currency_paste_symbols_test.rbfails whenCURRENCY_SYMBOLinparse_amount_paste.jsdrifts from the letter-free symbols inconfig/currencies.yml.- It's a Minitest rather than an
.mjstest because CI doesn't runtest/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.