Skip to content

Commit dfdadb5

Browse files
authored
Merge pull request rmosolgo#372 from rmosolgo/fix-lexer-unicode
fix(Lexer) replace backslash-u-escaped unicode
2 parents 5d868cf + 8d797ea commit dfdadb5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/graphql/compatibility/query_parser_specification.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_it_parses_inputs
5757
int: 3,
5858
float: 4.7e-24,
5959
bool: false,
60-
string: "☀︎🏆\\n \\" \u00b6 /",
60+
string: "☀︎🏆 \\b \\f \\n \\r \\t \\" \u00b6 \\u00b6 / \\/",
6161
enum: ENUM_NAME,
6262
array: [7, 8, 9]
6363
object: {a: [1,2,3], b: {c: "4"}}
@@ -71,7 +71,7 @@ def test_it_parses_inputs
7171
assert_equal 3, inputs[0].value, "Integers"
7272
assert_equal 0.47e-23, inputs[1].value, "Floats"
7373
assert_equal false, inputs[2].value, "Booleans"
74-
assert_equal %|☀︎🏆\n " ¶ /|, inputs[3].value, "Strings"
74+
assert_equal %|☀︎🏆 \b \f \n \r \t " ¶ ¶ / /|, inputs[3].value, "Strings"
7575
assert_instance_of GraphQL::Language::Nodes::Enum, inputs[4].value
7676
assert_equal "ENUM_NAME", inputs[4].value.name, "Enums"
7777
assert_equal [7,8,9], inputs[5].value, "Lists"

lib/graphql/language/lexer.rl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ module GraphQL
109109
# To avoid allocating more strings, this modifies the string passed into it
110110
def self.replace_escaped_characters_in_place(raw_string)
111111
raw_string.gsub!(ESCAPES, ESCAPES_REPLACE)
112+
raw_string.gsub!(UTF_8, &UTF_8_REPLACE)
112113
nil
113114
end
114115

@@ -177,6 +178,9 @@ module GraphQL
177178
"\\t" => "\t",
178179
}
179180

181+
UTF_8 = /\\u[\dAa-f]{4}/i
182+
UTF_8_REPLACE = ->(m) { [m[-4..-1].to_i(16)].pack('U'.freeze) }
183+
180184
def self.emit_string(ts, te, meta)
181185
value = meta[:data][ts...te].pack("c*").force_encoding("UTF-8")
182186
if value =~ /\\u|\\./ && value !~ ESCAPES

0 commit comments

Comments
 (0)