From 77e6b5e86ea87752139190561a74435ccb86fe5a Mon Sep 17 00:00:00 2001 From: ptmcg Date: Fri, 29 Apr 2016 15:15:27 +0000 Subject: Fixed similar backtracking issues in the C and C++ style comments git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@336 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b --- src/CHANGES | 4 +++- src/pyparsing.py | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/CHANGES b/src/CHANGES index 176a4d8..6bc0d09 100644 --- a/src/CHANGES +++ b/src/CHANGES @@ -10,7 +10,9 @@ Version 2.1.2 - - Fixed catastrophic regex backtracking in implementation of the quoted string expressions (dblQuotedString, sglQuotedString, and quotedString). Reported on the pyparsing wiki by webpentest, - good catch! + good catch! (Also tuned up some other expressions susceptible to the + same backtracking problem, such as cStyleComment, cppStyleComment, + etc.) Version 2.1.1 - March, 2016 diff --git a/src/pyparsing.py b/src/pyparsing.py index fc6a439..988419b 100644 --- a/src/pyparsing.py +++ b/src/pyparsing.py @@ -58,7 +58,7 @@ The pyparsing module handles some of the problems that are typically vexing when """ __version__ = "2.1.2" -__versionTime__ = "28 Apr 2016 22:32 UTC" +__versionTime__ = "29 Apr 2016 15:10 UTC" __author__ = "Paul McGuire " import string @@ -3815,12 +3815,12 @@ def replaceHTMLEntity(t): return _htmlEntityMap.get(t.entity) # it's easy to get these comment structures wrong - they're very common, so may as well make them available -cStyleComment = Regex(r"/\*(?:[^*]*\*+)+?/").setName("C style comment") +cStyleComment = Combine(Regex(r"/\*(?:[^*]|\*(?!/))*") + '*/').setName("C style comment") htmlComment = Regex(r"").setName("HTML comment") restOfLine = Regex(r".*").leaveWhitespace().setName("rest of line") -dblSlashComment = Regex(r"\/\/(\\\n|.)*").setName("// comment") -cppStyleComment = Regex(r"/(?:\*(?:[^*]*\*+)+?/|/[^\n]*(?:\n[^\n]*)*?(?:(?