Skip to content

Commit

Permalink
Optimize escape_single_quoted_newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Sep 10, 2024
1 parent 312e0a6 commit 5534a8f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/graphql/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ def self.escape_single_quoted_newlines(query_str)
inside_single_quoted_string = false
new_query_str = nil
while !scanner.eos?
if (match = scanner.scan(/(?:\\"|[^"\n\r]|""")+/m)) && new_query_str
new_query_str << match
elsif scanner.scan('"')
if scanner.skip(/(?:\\"|[^"\n\r]|""")+/m)
new_query_str && (new_query_str << scanner.matched)
elsif scanner.skip('"')
new_query_str && (new_query_str << '"')
inside_single_quoted_string = !inside_single_quoted_string
elsif scanner.scan("\n")
elsif scanner.skip("\n")
if inside_single_quoted_string
new_query_str ||= query_str[0, scanner.pos - 1]
new_query_str << '\\n'
else
new_query_str && (new_query_str << "\n")
end
elsif scanner.scan("\r")
elsif scanner.skip("\r")
if inside_single_quoted_string
new_query_str ||= query_str[0, scanner.pos - 1]
new_query_str << '\\r'
Expand Down

0 comments on commit 5534a8f

Please sign in to comment.