[BOTS-2355] escape single quote at the beginning of the string#4
Merged
drarbego merged 2 commits intoMar 26, 2019
Conversation
juanitodread
approved these changes
Mar 26, 2019
juanitodread
left a comment
There was a problem hiding this comment.
LGTM
This regex is getting hard to maintain. Should we start to think of a different solution?
diacus
reviewed
Mar 26, 2019
diacus
approved these changes
Mar 26, 2019
|
@juanitodread 🤔 May be, but I can't think in other scenarios for these kind of strings. |
|
What about something simpler using 'given string'.replace("'", "\\'") # single quotes case
.replace('"', '\\"') # double quotes case
.replace... # Any new case |
|
Wouldn't that break already scaped strings? |
|
It will if the string was already escaped... in that case import json
>>> json.dumps("this string already 'contains' \'escaped\' quotes") # single quotes case
'"this string already \'contains\' \'escaped\' quotes"'
>>> json.dumps('this string already "contains" \"escaped\" quotes') # double quotes case
'"this string already \\"contains\\" \\"escaped\\" quotes"' |
|
I like it. Plus it might fix bug BOTS-2357 as well. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes error when escaping single quotes in queries
What was the issue?
the regular expression used to match unescaped single quotes (
([^\\])) was not matching single quotes at the beginning of the string. so'facebook', 'webchat'resulted in'facebook\\', \\'webchat\\'