Skip to content

Commit

Permalink
trim whitespace on currency in helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
salimshopbou committed Dec 6, 2024
1 parent 8dd6e27 commit 5459c4e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/money/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def value_to_currency(currency)
Money::NULL_CURRENCY
when String
begin
Currency.find!(currency)
Currency.find!(currency.strip)
rescue Money::Currency::UnknownCurrency => error
if Money.config.legacy_deprecations
Money.deprecate(error.message)
Expand Down
4 changes: 4 additions & 0 deletions spec/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
expect(subject.value_to_currency('usd')).to eq(Money::Currency.new('USD'))
end

it 'trims whitespace ' do
expect(subject.value_to_currency(' usd ')).to eq(Money::Currency.new('USD'))
end

it 'returns the null currency when invalid iso is passed' do
configure(legacy_deprecations: true) do
expect(Money).to receive(:deprecate).once
Expand Down

0 comments on commit 5459c4e

Please sign in to comment.