diff --git a/CHANGES b/CHANGES index 5db5bb7d..94b34d98 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,10 @@ Version 3.0.7 - - Fixed bug #350, in which White expressions could fail to match due to unintended whitespace-skipping. Reported by Fu Hanxi, thank you! +- Fixed bug #355, when a QuotedString is defined with characters in its + quoteChar string containing regex-significant characters such as ., *, + ?, [, ], etc. + - Fixed bug in ParserElement.run_tests where comments would be displayed using with_line_numbers. diff --git a/pyparsing/__init__.py b/pyparsing/__init__.py index 4cc4f959..47b8e5cf 100644 --- a/pyparsing/__init__.py +++ b/pyparsing/__init__.py @@ -126,7 +126,7 @@ def __repr__(self): __version_info__ = version_info(3, 0, 7, "final", 0) -__version_time__ = "02 Jan 2022 22:56 UTC" +__version_time__ = "15 Jan 2022 04:10 UTC" __version__ = __version_info__.__version__ __versionTime__ = __version_time__ __author__ = "Paul McGuire " diff --git a/pyparsing/core.py b/pyparsing/core.py index cb9ac9ac..2ab7ea70 100644 --- a/pyparsing/core.py +++ b/pyparsing/core.py @@ -3131,7 +3131,7 @@ def __init__( + "|".join( "(?:{}(?!{}))".format( re.escape(self.endQuoteChar[:i]), - _escape_regex_range_chars(self.endQuoteChar[i:]), + re.escape(self.endQuoteChar[i:]), ) for i in range(len(self.endQuoteChar) - 1, 0, -1) ) diff --git a/tests/test_unit.py b/tests/test_unit.py index b92cc9cc..388af38f 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -1807,6 +1807,29 @@ def test(label, quoteExpr, expected): with self.assertRaises(ValueError): pp.QuotedString("", "\\") + def testCustomQuotes2(self): + + qs = pp.QuotedString(quote_char=".[", end_quote_char="].") + print(qs.reString) + self.assertParseAndCheckList(qs, ".[...].", ['...']) + self.assertParseAndCheckList(qs, ".[].", ['']) + self.assertParseAndCheckList(qs, ".[]].", [']']) + self.assertParseAndCheckList(qs, ".[]]].", [']]']) + + qs = pp.QuotedString(quote_char="+*", end_quote_char="*+") + print(qs.reString) + self.assertParseAndCheckList(qs, "+*...*+", ['...']) + self.assertParseAndCheckList(qs, "+**+", ['']) + self.assertParseAndCheckList(qs, "+***+", ['*']) + self.assertParseAndCheckList(qs, "+****+", ['**']) + + qs = pp.QuotedString(quote_char="*/", end_quote_char="/*") + print(qs.reString) + self.assertParseAndCheckList(qs, "*/.../*", ['...']) + self.assertParseAndCheckList(qs, "*//*", ['']) + self.assertParseAndCheckList(qs, "*///*", ['/']) + self.assertParseAndCheckList(qs, "*////*", ['//']) + def testRepeater(self): if ParserElement._packratEnabled or ParserElement._left_recursion_enabled: print("skipping this test, not compatible with memoization")