From 9721e5403580015bdc692fcf8a92201317186ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szczepan=20Bu=C5=82at?= Date: Wed, 4 Jun 2025 18:13:37 +0200 Subject: [PATCH 1/2] Improve handling multiple delimeters in input --- Gemfile | 4 ++++ lib/monetize/parser.rb | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index c496b36451..14dee0295b 100644 --- a/Gemfile +++ b/Gemfile @@ -10,4 +10,8 @@ elsif RUBY_VERSION =~ /^1/ gem 'i18n', '~> 0.9' end +if RUBY_VERSION >= '3.4.0' + gem 'bigdecimal' +end + gemspec diff --git a/lib/monetize/parser.rb b/lib/monetize/parser.rb index 8d88c09a67..79f2645ecd 100644 --- a/lib/monetize/parser.rb +++ b/lib/monetize/parser.rb @@ -184,8 +184,10 @@ def regex_safe_symbols end def split_major_minor(num, delimiter) - major, minor = num.split(delimiter) - [major, minor || '00'] + splits = num.split(delimiter) + fail ParseError, 'Invalid amount (multiple delimiters)' if splits.length > 2 + + [splits[0], splits[1] || '00'] end def currency_symbol_regex From 5f20048f61caf049f222edb7abdab6b809ad1474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szczepan=20Bu=C5=82at?= Date: Tue, 1 Jul 2025 13:48:54 +0200 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c08d55ab1..beddb1ce0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Current +- Fix parsing multiple delimeters in the amount, after BigDecimal updates + ## 1.13.0 - **Breaking change**: check ISO currency code validity when parsing strings with `to_money` - Adds `expect_whole_subunits` option when fractional subunits are expected