-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle escaping % character in query #90
Handle escaping % character in query #90
Conversation
pinotdb/db.py
Outdated
|
||
|
||
def escape_operation(value: str) -> str: | ||
return value.replace('%', '%%').replace('%(', '(') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One concern I have is what if users are already handling this escaping while sending the query. Should we handle that with return value.replace('%%', '%')replace('%', '%%').replace('%(', '(')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case maybe you can do
value.replace('%%', '%').replace('%', '%%').replace('%(', '(')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or make it a place holder, then convert it back, e.g.
import re
def convert_percent_correctly(text):
# First, temporarily replace '%%' with a placeholder to avoid modifying them
temp_placeholder = "TEMP_DOUBLE_PERCENT"
text = text.replace('%%', temp_placeholder)
# Then, convert standalone '%' to '%%'
text = re.sub(r'%(?!\()', '%%', text)
# Finally, replace the placeholder back to '%%'
text = text.replace(temp_placeholder, '%%')
return text
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's much cleaner!
This addresses the issue mentioned in #10