python driver: preserve trailing quotes in agtype string values#2425
Open
SAY-5 wants to merge 1 commit intoapache:masterfrom
Open
python driver: preserve trailing quotes in agtype string values#2425SAY-5 wants to merge 1 commit intoapache:masterfrom
SAY-5 wants to merge 1 commit intoapache:masterfrom
Conversation
str.strip('"') in visitStringValue() and visitPair() removes every '"'
on either side of the token, not just the outer delimiters, so a value
ending in an escaped quote (e.g. '"foo \"bar\""') loses its trailing
backslash-escaped '"' character. The Agtype grammar guarantees STRING
tokens always carry exactly one delimiter on each side, so slice with
[1:-1] to strip them precisely.
Fixes apache#2418
Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
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.
Fixes #2418.
ResultVisitor.visitStringValue()andvisitPair()indrivers/python/age/builder.pyusestr.strip('"')to remove the surrounding delimiters from agtype STRING tokens.str.strip()removes all matching characters from both ends, so when a property value or object key starts or ends with an escaped quote the parser drops the data character along with the delimiter:"foo \"bar\""foo \"bar\"foo \"bar\"\"leading"\"leadingleading"trailing\""trailing\"trailing\The Agtype grammar (
drivers/Agtype.g4) guaranteesSTRING : '"' (ESC | SAFECODEPOINT)* '"', so the token always has exactly one"delimiter on each side. Slicing with[1:-1]removes them precisely without touching the body.Test added:
test_string_value_preserves_inner_quotescovers leading/trailing/embedded escaped quotes plus thevisitPair()path for object keys, and exercises the empty-string""edge case.