summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-04-29 15:15:27 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-04-29 15:15:27 +0000
commit77e6b5e86ea87752139190561a74435ccb86fe5a (patch)
tree82c6118f2c875349da34398c12882a5ba2d60aa7 /src
parentb0adb1a172dafe3d2dc743dd02baede7197a5276 (diff)
downloadpyparsing-77e6b5e86ea87752139190561a74435ccb86fe5a.tar.gz
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
Diffstat (limited to 'src')
-rw-r--r--src/CHANGES4
-rw-r--r--src/pyparsing.py8
2 files changed, 7 insertions, 5 deletions
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 <ptmcg@users.sourceforge.net>"
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"<!--[\s\S]*?-->").setName("HTML comment")
restOfLine = Regex(r".*").leaveWhitespace().setName("rest of line")
-dblSlashComment = Regex(r"\/\/(\\\n|.)*").setName("// comment")
-cppStyleComment = Regex(r"/(?:\*(?:[^*]*\*+)+?/|/[^\n]*(?:\n[^\n]*)*?(?:(?<!\\)|\Z))").setName("C++ style comment")
+dblSlashComment = Regex(r"//(?:\\\n|[^\n])*").setName("// comment")
+cppStyleComment = Combine(Regex(r"/\*(?:[^*]|\*(?!/))*") + '*/'| dblSlashComment).setName("C++ style comment")
javaStyleComment = cppStyleComment
pythonStyleComment = Regex(r"#.*").setName("Python style comment")