Skip to content

Commit 8d8a06a

Browse files
committed
Handle stray hyphens in Ruby parser
1 parent 4315fb1 commit 8d8a06a

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

lib/graphql/language/lexer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def debug_token_value(token_name)
8989
"..."
9090
elsif token_name == :STRING
9191
string_value
92+
elsif @scanner.matched_size.nil?
93+
@scanner.peek(1)
9294
else
9395
token_value
9496
end

lib/graphql/language/parser.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,7 @@ def expect_token_value(tok)
739739
# token_value works for when the scanner matched something
740740
# which is usually fine and it's good for it to be fast at that.
741741
def debug_token_value
742-
if token_name && Lexer::Punctuation.const_defined?(token_name)
743-
Lexer::Punctuation.const_get(token_name)
744-
elsif token_name == :ELLIPSIS
745-
"..."
746-
else
747-
@lexer.token_value
748-
end
742+
@lexer.debug_token_value(token_name)
749743
end
750744
end
751745
end

spec/graphql/language/parser_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@
5454
assert_equal expected_msg, err.message
5555
end
5656

57+
it "handles hyphens with errors" do
58+
err = assert_raises(GraphQL::ParseError) {
59+
GraphQL.parse("{ field(argument:a-b) }")
60+
}
61+
expected_msg = if USING_C_PARSER
62+
"syntax error, unexpected invalid token (\"-\") at [1, 19]"
63+
else
64+
"Expected NAME, actual: INT (\"-\") at [1, 19]"
65+
end
66+
67+
assert_equal expected_msg, err.message
68+
end
69+
5770
describe "anonymous fragment extension" do
5871
let(:document) { GraphQL.parse(query_string) }
5972
let(:query_string) {%|

0 commit comments

Comments
 (0)