Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/graphql/compatibility/query_parser_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_it_parses_inputs
int: 3,
float: 4.7e-24,
bool: false,
string: "☀︎🏆\\n \\" \u00b6 /",
string: "☀︎🏆 \\b \\f \\n \\r \\t \\" \u00b6 \\u00b6 / \\/",
enum: ENUM_NAME,
array: [7, 8, 9]
object: {a: [1,2,3], b: {c: "4"}}
Expand All @@ -71,7 +71,7 @@ def test_it_parses_inputs
assert_equal 3, inputs[0].value, "Integers"
assert_equal 0.47e-23, inputs[1].value, "Floats"
assert_equal false, inputs[2].value, "Booleans"
assert_equal %|☀︎🏆\n " ¶ /|, inputs[3].value, "Strings"
assert_equal %|☀︎🏆 \b \f \n \r \t " ¶ ¶ / /|, inputs[3].value, "Strings"
assert_instance_of GraphQL::Language::Nodes::Enum, inputs[4].value
assert_equal "ENUM_NAME", inputs[4].value.name, "Enums"
assert_equal [7,8,9], inputs[5].value, "Lists"
Expand Down
4 changes: 4 additions & 0 deletions lib/graphql/language/lexer.rl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module GraphQL
# To avoid allocating more strings, this modifies the string passed into it
def self.replace_escaped_characters_in_place(raw_string)
raw_string.gsub!(ESCAPES, ESCAPES_REPLACE)
raw_string.gsub!(UTF_8, &UTF_8_REPLACE)
nil
end

Expand Down Expand Up @@ -177,6 +178,9 @@ module GraphQL
"\\t" => "\t",
}

UTF_8 = /\\u[\dAa-f]{4}/i
UTF_8_REPLACE = ->(m) { [m[-4..-1].to_i(16)].pack('U'.freeze) }

def self.emit_string(ts, te, meta)
value = meta[:data][ts...te].pack("c*").force_encoding("UTF-8")
if value =~ /\\u|\\./ && value !~ ESCAPES
Expand Down