Skip to content

python driver: preserve trailing quotes in agtype string values#2425

Open
SAY-5 wants to merge 1 commit intoapache:masterfrom
SAY-5:fix/python-string-strip-quotes
Open

python driver: preserve trailing quotes in agtype string values#2425
SAY-5 wants to merge 1 commit intoapache:masterfrom
SAY-5:fix/python-string-strip-quotes

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented May 7, 2026

Fixes #2418.

ResultVisitor.visitStringValue() and visitPair() in drivers/python/age/builder.py use str.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:

Input agtype Expected Before this PR
"foo \"bar\"" foo \"bar\" foo \"bar\
"\"leading" \"leading leading
"trailing\"" trailing\" trailing\

The Agtype grammar (drivers/Agtype.g4) guarantees STRING : '"' (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_quotes covers leading/trailing/embedded escaped quotes plus the visitPair() path for object keys, and exercises the empty-string "" edge case.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python driver: Double quotes at the end of string values are wrongfully removed

1 participant