summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2014-04-29 19:47:46 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2014-04-29 19:47:46 +0000
commitda6295a6f05e313a57208249cd939bd6f3f6d966 (patch)
tree20541da9a7fc543a64ac47f4896becc922e2a6c2
parent8ddf64d2fada52b295769c7bd55a2e7d321caef9 (diff)
downloadpyparsing-da6295a6f05e313a57208249cd939bd6f3f6d966.tar.gz
Fixed escaping behavior in QuotedString. Formerly, only quotation
marks (or characters designated as quotation marks in the QuotedString constructor) would be escaped. Now all escaped characters will be escaped, and the escaping backslashes will be removed. git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@268 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--src/CHANGES8
-rw-r--r--src/pyparsing.py7
-rw-r--r--src/unitTests.py17
3 files changed, 21 insertions, 11 deletions
diff --git a/src/CHANGES b/src/CHANGES
index 681a7b7..1225f6a 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -2,6 +2,14 @@
Change Log
==========
+Version 2.0.3 -
+---------------------------
+- Fixed escaping behavior in QuotedString. Formerly, only quotation
+ marks (or characters designated as quotation marks in the QuotedString
+ constructor) would be escaped. Now all escaped characters will be
+ escaped, and the escaping backslashes will be removed.
+
+
Version 2.0.2 - April, 2014
---------------------------
- Extended "expr(name)" shortcut (same as "expr.setResultsName(name)")
diff --git a/src/pyparsing.py b/src/pyparsing.py
index 7dfe104..c8db75a 100644
--- a/src/pyparsing.py
+++ b/src/pyparsing.py
@@ -57,8 +57,8 @@ The pyparsing module handles some of the problems that are typically vexing when
- embedded comments
"""
-__version__ = "2.0.2"
-__versionTime__ = "13 April 2014 12:10"
+__version__ = "2.0.3"
+__versionTime__ = "28 April 2014 17:10"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -1914,8 +1914,7 @@ class QuotedString(Token):
self.pattern += (r'|(?:%s)' % re.escape(escQuote))
if escChar:
self.pattern += (r'|(?:%s.)' % re.escape(escChar))
- charset = ''.join(set(self.quoteChar[0]+self.endQuoteChar[0])).replace('^',r'\^').replace('-',r'\-')
- self.escCharReplacePattern = re.escape(self.escChar)+("([%s])" % charset)
+ self.escCharReplacePattern = re.escape(self.escChar)+"(.)"
self.pattern += (r')*%s' % re.escape(self.endQuoteChar))
try:
diff --git a/src/unitTests.py b/src/unitTests.py
index f463a3b..72419e7 100644
--- a/src/unitTests.py
+++ b/src/unitTests.py
@@ -927,15 +927,17 @@ class CustomQuotesTest(ParseTestCase):
print_(quoteExpr.pattern)
print_(quoteExpr.searchString(testString))
print_(quoteExpr.searchString(testString)[0][0])
+ print_(expected)
assert quoteExpr.searchString(testString)[0][0] == expected, \
"failed to match %s, expected '%s', got '%s'" % \
(quoteExpr,expected,quoteExpr.searchString(testString)[0])
+ print_()
test(colonQuotes, r"sdf:jls:djf")
- test(dashQuotes, r"sdf\:jls::-djf: sl")
- test(hatQuotes, r"sdf\:jls")
- test(hatQuotes1, r"sdf\:jls^--djf")
- test(dblEqQuotes, r"sdf\:j=ls::--djf: sl")
+ test(dashQuotes, r"sdf:jls::-djf: sl")
+ test(hatQuotes, r"sdf:jls")
+ test(hatQuotes1, r"sdf:jls^--djf")
+ test(dblEqQuotes, r"sdf:j=ls::--djf: sl")
test( QuotedString(':::'), 'jls::--djf: sl')
test( QuotedString('==',endQuoteChar='--'), r'sdf\:j=lz::')
test( QuotedString('^^^',multiline=True), r"""==sdf\:j=lz::--djf: sl=^^=kfsjf
@@ -2411,7 +2413,8 @@ def makeTestSuiteTemp():
suite.addTest( PyparsingTestInit() )
#~ suite.addTest( OptionalEachTest() )
#~ suite.addTest( RepeaterTest() )
- suite.addTest( LocatedExprTest() )
+ #~ suite.addTest( LocatedExprTest() )
+ suite.addTest( CustomQuotesTest() )
return suite
@@ -2427,8 +2430,8 @@ console = True
if console:
#~ # console mode
testRunner = TextTestRunner()
- testRunner.run( makeTestSuite() )
- #~ testRunner.run( makeTestSuiteTemp() )
+ #~ testRunner.run( makeTestSuite() )
+ testRunner.run( makeTestSuiteTemp() )
#~ lp.run("testRunner.run( makeTestSuite() )")
else:
# HTML mode