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

Commit

Permalink
Fix parser handling of endash'es
Browse files Browse the repository at this point in the history
Use `unicode:characters_to_binary` instead of `list_to_binary`
  • Loading branch information
Josh Price committed Sep 12, 2016
1 parent 4969041 commit 96642e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/graphql_parser.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Erlang code.

extract_atom({Value, _Line}) -> Value.
extract_token({_Token, _Line, Value}) -> list_to_binary(Value).
extract_quoted_string_token({_Token, _Line, Value}) -> list_to_binary(lists:sublist(Value, 2, length(Value) - 2)).
extract_quoted_string_token({_Token, _Line, Value}) -> unicode:characters_to_binary(lists:sublist(Value, 2, length(Value) - 2)).
extract_integer({_Token, _Line, Value}) -> {Int, []} = string:to_integer(Value), Int.
extract_float({_Token, _Line, Value}) -> {Float, []} = string:to_float(Value), Float.
extract_boolean({_Token, _Line, "true"}) -> true;
Expand Down
5 changes: 5 additions & 0 deletions test/graphql/lang/parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ defmodule GraphQL.Lang.Parser.ParserTest do
assert_parse "{}", %{errors: [%{"message" => "GraphQL: syntax error before: '}' on line 1", "line_number" => 1}]}, :error
end

test "Handle unicode in string values" do
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}}
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}}
end

test "simple selection set" do
assert_parse "{ hero }",
%{kind: :Document,
Expand Down

0 comments on commit 96642e6

Please sign in to comment.