Skip to content

Commit 6b762ba

Browse files
committed
Correctly format unicode token parser exceptions
Fixes #107.
1 parent 282188a commit 6b762ba

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/poison/parser.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ defmodule Poison.ParseError do
2323
end
2424

2525
defp escape(token) do
26-
{value, _} = Identifier.escape(<<token>>, ?\\)
26+
{value, _} = Identifier.escape(<<token::utf8>>, ?\\)
2727
value
2828
end
2929
end
@@ -350,7 +350,7 @@ defmodule Poison.Parser do
350350
## Errors
351351

352352
defp syntax_error(<<token::utf8>> <> _, pos) do
353-
raise %ParseError{pos: pos, value: <<token>>}
353+
raise %ParseError{pos: pos, value: <<token::utf8>>}
354354
end
355355

356356
defp syntax_error(_, pos) do

test/poison/parser_test.exs

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ defmodule Poison.ParserTest do
8888
parse!(~s("𝄞))
8989
end
9090

91+
assert_raise ParseError, "Unexpected token at position 0: á", fn ->
92+
parse!(~s(á))
93+
end
94+
9195
assert_raise ParseError, "Unexpected token at position 0: \\x1F", fn ->
9296
parse!(~s(\u001F))
9397
end

0 commit comments

Comments
 (0)