@@ -105,14 +105,16 @@ def visitAgValue(self, ctx:AgtypeParser.AgValueContext):
105105 return valueCtx .accept (self )
106106
107107
108+ @staticmethod
109+ def _stripStringDelimiters (stringToken ):
110+ # The STRING token always has surrounding '"' delimiters per the
111+ # Agtype grammar; slice rather than strip('"') so escaped quotes
112+ # at the boundaries are preserved.
113+ return stringToken .getText ()[1 :- 1 ]
114+
108115 # Visit a parse tree produced by AgtypeParser#StringValue.
109116 def visitStringValue (self , ctx :AgtypeParser .StringValueContext ):
110- # The STRING token always has surrounding '"' delimiters per the
111- # Agtype grammar. str.strip('"') would also drop any '"' characters
112- # that are part of the actual data when the value starts or ends
113- # with an escaped quote, e.g. '"foo \\"bar\\""' -> 'foo \\"bar\\',
114- # so trim exactly the first and last character instead.
115- return ctx .STRING ().getText ()[1 :- 1 ]
117+ return self ._stripStringDelimiters (ctx .STRING ())
116118
117119
118120 # Visit a parse tree produced by AgtypeParser#IntegerValue.
@@ -187,8 +189,7 @@ def visitPair(self, ctx:AgtypeParser.PairContext):
187189 raise AGTypeError (ctx .getText (), "Missing key in object pair" )
188190 if agValNode is None :
189191 raise AGTypeError (ctx .getText (), "Missing value in object pair" )
190- # See visitStringValue() for why we slice instead of using strip('"').
191- return (strNode .getText ()[1 :- 1 ] , agValNode )
192+ return (self ._stripStringDelimiters (strNode ), agValNode )
192193
193194
194195 # Visit a parse tree produced by AgtypeParser#array.
0 commit comments