Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 96642e6

Browse files
author
Josh Price
committed
Fix parser handling of endash'es
Use `unicode:characters_to_binary` instead of `list_to_binary`
1 parent 4969041 commit 96642e6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/graphql_parser.yrl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Erlang code.
210210

211211
extract_atom({Value, _Line}) -> Value.
212212
extract_token({_Token, _Line, Value}) -> list_to_binary(Value).
213-
extract_quoted_string_token({_Token, _Line, Value}) -> list_to_binary(lists:sublist(Value, 2, length(Value) - 2)).
213+
extract_quoted_string_token({_Token, _Line, Value}) -> unicode:characters_to_binary(lists:sublist(Value, 2, length(Value) - 2)).
214214
extract_integer({_Token, _Line, Value}) -> {Int, []} = string:to_integer(Value), Int.
215215
extract_float({_Token, _Line, Value}) -> {Float, []} = string:to_float(Value), Float.
216216
extract_boolean({_Token, _Line, "true"}) -> true;

test/graphql/lang/parser_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ defmodule GraphQL.Lang.Parser.ParserTest do
1010
assert_parse "{}", %{errors: [%{"message" => "GraphQL: syntax error before: '}' on line 1", "line_number" => 1}]}, :error
1111
end
1212

13+
test "Handle unicode in string values" do
14+
assert_parse ~S[{ f(a: "é")}], %{definitions: [%{kind: :OperationDefinition, loc: %{start: 0}, operation: :query, selectionSet: %{kind: :SelectionSet, loc: %{start: 0}, selections: [%{arguments: [%{kind: :Argument, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "a"}, value: %{kind: :StringValue, loc: %{start: 0}, value: "é"}}], kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "f"}}]}}], kind: :Document, loc: %{start: 0}}
15+
assert_parse ~S[{ f(a: "–")}], %{definitions: [%{kind: :OperationDefinition, loc: %{start: 0}, operation: :query, selectionSet: %{kind: :SelectionSet, loc: %{start: 0}, selections: [%{arguments: [%{kind: :Argument, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "a"}, value: %{kind: :StringValue, loc: %{start: 0}, value: "–"}}], kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "f"}}]}}], kind: :Document, loc: %{start: 0}}
16+
end
17+
1318
test "simple selection set" do
1419
assert_parse "{ hero }",
1520
%{kind: :Document,

0 commit comments

Comments
 (0)