You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by "SAY-5 (via GitHub)" <gi...@apache.org> on 2026/05/07 08:20:35 UTC
[PR] python driver: preserve trailing quotes in agtype string values [age]
SAY-5 opened a new pull request, #2425:
URL: https://github.com/apache/age/pull/2425
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] python driver: preserve trailing quotes in agtype string values [age]
Posted by "SAY-5 (via GitHub)" <gi...@apache.org>.
SAY-5 commented on PR #2425:
URL: https://github.com/apache/age/pull/2425#issuecomment-4517549397
@jrgemignani Addressed all four Copilot comments in e2654254: centralized the trim logic into _stripStringDelimiters and reused it in both visitStringValue/visitPair, removed the stray space before the comma, and reformatted the test docstring. Replied on each inline thread.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] python driver: preserve trailing quotes in agtype string values [age]
Posted by "SAY-5 (via GitHub)" <gi...@apache.org>.
SAY-5 commented on PR #2425:
URL: https://github.com/apache/age/pull/2425#issuecomment-4531059641
Rebased on current master.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] python driver: preserve trailing quotes in agtype string values [age]
Posted by "SAY-5 (via GitHub)" <gi...@apache.org>.
SAY-5 commented on PR #2425:
URL: https://github.com/apache/age/pull/2425#issuecomment-4444281547
Rebased onto master.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] python driver: preserve trailing quotes in agtype string values [age]
Posted by "jrgemignani (via GitHub)" <gi...@apache.org>.
jrgemignani merged PR #2425:
URL: https://github.com/apache/age/pull/2425
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] python driver: preserve trailing quotes in agtype string values [age]
Posted by "SAY-5 (via GitHub)" <gi...@apache.org>.
SAY-5 commented on code in PR #2425:
URL: https://github.com/apache/age/pull/2425#discussion_r3279670863
##########
drivers/python/age/builder.py:
##########
@@ -107,7 +107,12 @@ def visitAgValue(self, ctx:AgtypeParser.AgValueContext):
# Visit a parse tree produced by AgtypeParser#StringValue.
def visitStringValue(self, ctx:AgtypeParser.StringValueContext):
- return ctx.STRING().getText().strip('"')
+ # The STRING token always has surrounding '"' delimiters per the
+ # Agtype grammar. str.strip('"') would also drop any '"' characters
+ # that are part of the actual data when the value starts or ends
+ # with an escaped quote, e.g. '"foo \\"bar\\""' -> 'foo \\"bar\\',
+ # so trim exactly the first and last character instead.
+ return ctx.STRING().getText()[1:-1]
Review Comment:
Centralized into a small `_stripStringDelimiters` helper.
##########
drivers/python/age/builder.py:
##########
@@ -182,7 +187,8 @@ def visitPair(self, ctx:AgtypeParser.PairContext):
raise AGTypeError(ctx.getText(), "Missing key in object pair")
if agValNode is None:
raise AGTypeError(ctx.getText(), "Missing value in object pair")
- return (strNode.getText().strip('"') , agValNode)
+ # See visitStringValue() for why we slice instead of using strip('"').
+ return (strNode.getText()[1:-1] , agValNode)
Review Comment:
Both call sites now use `_stripStringDelimiters`.
##########
drivers/python/age/builder.py:
##########
@@ -182,7 +187,8 @@ def visitPair(self, ctx:AgtypeParser.PairContext):
raise AGTypeError(ctx.getText(), "Missing key in object pair")
if agValNode is None:
raise AGTypeError(ctx.getText(), "Missing value in object pair")
- return (strNode.getText().strip('"') , agValNode)
+ # See visitStringValue() for why we slice instead of using strip('"').
+ return (strNode.getText()[1:-1] , agValNode)
Review Comment:
Removed the stray space.
##########
drivers/python/test_agtypes.py:
##########
@@ -245,6 +245,20 @@ def test_array_of_mixed_types(self):
self.assertEqual(result[4], [1, 2, 3])
self.assertEqual(result[5], {"key": "val"})
+ def test_string_value_preserves_inner_quotes(self):
+ """Issue #2418: visitStringValue must remove only the outer quote
+ delimiters, not every '"' on either side, otherwise values that end
+ with an escaped quote (e.g. '"foo \\"bar\\""') lose data."""
Review Comment:
Reformatted to summary + body + closing quotes on their own line.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] python driver: preserve trailing quotes in agtype string values [age]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2425:
URL: https://github.com/apache/age/pull/2425#discussion_r3235534583
##########
drivers/python/age/builder.py:
##########
@@ -107,7 +107,12 @@ def visitAgValue(self, ctx:AgtypeParser.AgValueContext):
# Visit a parse tree produced by AgtypeParser#StringValue.
def visitStringValue(self, ctx:AgtypeParser.StringValueContext):
- return ctx.STRING().getText().strip('"')
+ # The STRING token always has surrounding '"' delimiters per the
+ # Agtype grammar. str.strip('"') would also drop any '"' characters
+ # that are part of the actual data when the value starts or ends
+ # with an escaped quote, e.g. '"foo \\"bar\\""' -> 'foo \\"bar\\',
+ # so trim exactly the first and last character instead.
+ return ctx.STRING().getText()[1:-1]
Review Comment:
The delimiter-trimming logic is now duplicated in both `visitStringValue()` and `visitPair()`. Consider centralizing it in a small helper (e.g., a private method) so any future changes to STRING token handling (or additional validation/normalization) only need to be made in one place.
##########
drivers/python/age/builder.py:
##########
@@ -182,7 +187,8 @@ def visitPair(self, ctx:AgtypeParser.PairContext):
raise AGTypeError(ctx.getText(), "Missing key in object pair")
if agValNode is None:
raise AGTypeError(ctx.getText(), "Missing value in object pair")
- return (strNode.getText().strip('"') , agValNode)
+ # See visitStringValue() for why we slice instead of using strip('"').
+ return (strNode.getText()[1:-1] , agValNode)
Review Comment:
The delimiter-trimming logic is now duplicated in both `visitStringValue()` and `visitPair()`. Consider centralizing it in a small helper (e.g., a private method) so any future changes to STRING token handling (or additional validation/normalization) only need to be made in one place.
##########
drivers/python/test_agtypes.py:
##########
@@ -245,6 +245,20 @@ def test_array_of_mixed_types(self):
self.assertEqual(result[4], [1, 2, 3])
self.assertEqual(result[5], {"key": "val"})
+ def test_string_value_preserves_inner_quotes(self):
+ """Issue #2418: visitStringValue must remove only the outer quote
+ delimiters, not every '"' on either side, otherwise values that end
+ with an escaped quote (e.g. '"foo \\"bar\\""') lose data."""
Review Comment:
This multi-line docstring is a bit hard to read as written. Consider reformatting to follow typical Python docstring conventions (short summary line, blank line, then details; closing quotes on their own line) to improve readability and consistency with other tests.
##########
drivers/python/age/builder.py:
##########
@@ -182,7 +187,8 @@ def visitPair(self, ctx:AgtypeParser.PairContext):
raise AGTypeError(ctx.getText(), "Missing key in object pair")
if agValNode is None:
raise AGTypeError(ctx.getText(), "Missing value in object pair")
- return (strNode.getText().strip('"') , agValNode)
+ # See visitStringValue() for why we slice instead of using strip('"').
+ return (strNode.getText()[1:-1] , agValNode)
Review Comment:
There is an extra space before the comma in the returned tuple. Removing it aligns with standard Python formatting conventions and avoids whitespace-only churn in future diffs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] python driver: preserve trailing quotes in agtype string values [age]
Posted by "jrgemignani (via GitHub)" <gi...@apache.org>.
jrgemignani commented on PR #2425:
URL: https://github.com/apache/age/pull/2425#issuecomment-4446134003
@SAY-5 Can you address Copilot's comments above? Please address then in each comment :) It makes it easier to verify.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] python driver: preserve trailing quotes in agtype string values [age]
Posted by "jrgemignani (via GitHub)" <gi...@apache.org>.
jrgemignani commented on PR #2425:
URL: https://github.com/apache/age/pull/2425#issuecomment-4442521499
@SAY-5 Please rebase :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org