Skip to content

QuotedString's escQuote parameter does not work unless it is a double char #263

@MrHen

Description

@MrHen

Using pyparsing-2.4.7:

>>> from pyparsing import QuotedString
>>> quoted = QuotedString(quoteChar="\"", escChar=None, escQuote="\\\"")
>>> quoted.parseString('"abc"')
(['abc'], {})
>>> quoted.parseString('"abc \"def\""')
(['abc '], {})

I am expecting the second example to return the entire string. A slightly easier case to read:

>>> quoted = QuotedString(quoteChar="y", escChar=None, escQuote="xy")
>>> quoted.parseString('yaaay')
(['aaa'], {})
quoted.parseString('yaaaxyaaay')
>>> quoted.parseString('yaaaxyaaay')
(['aaax'], {})

Compare both of the above with the use of a double:

>>> quoted = QuotedString(quoteChar="y", escChar=None, escQuote="yy")
>>> quoted.parseString('yaaay')
(['aaa'], {})
quoted.parseString('yaaayyaaay')
>>> quoted.parseString('yaaayyaaay')
(['aaayaaa'], {})

Looking at the code, the reason appears to be regex fun:

>>> quoted = QuotedString(quoteChar="y", escChar=None, escQuote="xy")
>>> quoted.pattern
'y(?:[^y\\n\\r]|(?:xy))*y'

This regex will not match yaaaxyaaay: https://regexr.com/5km7f

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions