Skip to content

Commit

Permalink
Merge pull request #5095 from rmosolgo/optimize-escape-newline
Browse files Browse the repository at this point in the history
Optimize escape_single_quoted_newlines
  • Loading branch information
rmosolgo authored Sep 10, 2024
2 parents 312e0a6 + 5534a8f commit e1fdd9b
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 e1fdd9b

Please sign in to comment.