File tree Expand file tree Collapse file tree 4 files changed +31
-12
lines changed Expand file tree Collapse file tree 4 files changed +31
-12
lines changed Original file line number Diff line number Diff line change @@ -114,23 +114,20 @@ def string_value
114
114
is_block = str . start_with? ( '"""' )
115
115
if is_block
116
116
str . gsub! ( /\A """|"""\z / , '' )
117
+ return Language ::BlockString . trim_whitespace ( str )
117
118
else
118
119
str . gsub! ( /\A "|"\z / , '' )
119
- end
120
120
121
- if is_block
122
- str = Language ::BlockString . trim_whitespace ( str )
123
- end
124
-
125
- if !str . valid_encoding? || !str . match? ( VALID_STRING )
126
- raise_parse_error ( "Bad unicode escape in #{ str . inspect } " )
127
- else
128
- Lexer . replace_escaped_characters_in_place ( str )
129
-
130
- if !str . valid_encoding?
121
+ if !str . valid_encoding? || !str . match? ( VALID_STRING )
131
122
raise_parse_error ( "Bad unicode escape in #{ str . inspect } " )
132
123
else
133
- str
124
+ Lexer . replace_escaped_characters_in_place ( str )
125
+
126
+ if !str . valid_encoding?
127
+ raise_parse_error ( "Bad unicode escape in #{ str . inspect } " )
128
+ else
129
+ str
130
+ end
134
131
end
135
132
end
136
133
end
Original file line number Diff line number Diff line change
1
+ {
2
+ example1 : getString (string : " \u0064 " ) # should return "d"
3
+ example2 : getString (string : " \\ u0064" ) # should return "\\u0064"
4
+ # example3: getString(string: "\u006") # validation error
5
+ example4 : getString (string : " \\ u006" ) # should return "\\u006"
6
+ }
Original file line number Diff line number Diff line change
1
+ query bug2 {
2
+ example1 : getString (string : " " "\a""" ) # should be "\\a"
3
+ example2 : getString (string : " " "\u006""" ) # should be "\\u006"
4
+ example3 : getString (string : " " "\n""" ) # should be "\\n"
5
+ example4 : getString (string : " " "\u0064""" ) # should be "\\u0064"
6
+ }
Original file line number Diff line number Diff line change @@ -129,5 +129,15 @@ def get_string(string:)
129
129
res2 = UnicodeEscapeSchema . execute ( error_query_str )
130
130
assert_equal [ "Expected string or block string, but it was malformed" ] , res2 [ "errors" ] . map { |err | err [ "message" ] }
131
131
end
132
+
133
+ it "parses escapes properly in triple-quoted strings" do
134
+ query_str = File . read ( "./spec/fixtures/unicode_escapes/query2.graphql" )
135
+ res = UnicodeEscapeSchema . execute ( query_str )
136
+ # No replacing in block strings:
137
+ assert_equal "\\ a" , res [ "data" ] [ "example1" ]
138
+ assert_equal "\\ u006" , res [ "data" ] [ "example2" ]
139
+ assert_equal "\\ n" , res [ "data" ] [ "example3" ]
140
+ assert_equal "\\ u0064" , res [ "data" ] [ "example4" ]
141
+ end
132
142
end
133
143
end
You can’t perform that action at this time.
0 commit comments