Skip to content

Commit

Permalink
Fix parsing money strings with unicode symbols. Closes #95
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Feb 12, 2019
1 parent 6aa3e10 commit b37d15a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Changelog for Money v3.2.3

This is the changelog for Money v3.2.3 released on February 12th, 2019. For older changelogs please consult the release tag on [GitHub](https://github.com/kipcole9/money/tags)

### Bug Fixes

* Correctly parse money strings with unicode currency symbols like "€". Closes #95. Thanks to @crbelaus.

# Changelog for Money v3.2.2

This is the changelog for Money v3.2.2 released on February 10th, 2019. For older changelogs please consult the release tag on [GitHub](https://github.com/kipcole9/money/tags)
Expand Down
2 changes: 1 addition & 1 deletion lib/money.ex
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ defmodule Money do
# @doc since: "3.2.0"
@currency "[^0-9,. ]*"
@amount "[0-9][0-9,. ]+"
@regex Regex.compile!("^(?<cb>#{@currency})?(?<amount>#{@amount})?(?<ca>#{@currency})?$")
@regex Regex.compile!("^(?<cb>#{@currency})?(?<amount>#{@amount})?(?<ca>#{@currency})?$", [:unicode])
@spec parse(String.t(), Keyword.t()) :: Money.t() | {:error, {Exception.t(), String.t()}}
def parse(string, options \\ [])

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Money.Mixfile do
use Mix.Project

@version "3.2.2"
@version "3.2.3"

def project do
[
Expand Down
4 changes: 4 additions & 0 deletions test/money_parse_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ defmodule MoneyTest.Parse do
assert Money.parse("100,00USD", locale: "de") == Money.new(:USD, "100.00")
end

test "parses euro (unicode symbol)" do
assert Money.parse("99.99€") == Money.new(:EUR, "99.99")
end

test "parsing fails" do
assert Money.parse("100") ==
{:error,
Expand Down

0 comments on commit b37d15a

Please sign in to comment.