Skip to content

Commit

Permalink
unescape: Handle backslashes before end of string
Browse files Browse the repository at this point in the history
Fixes #483.
  • Loading branch information
Makman2 authored and sils committed Apr 28, 2015
1 parent 4ff6ebc commit b5629cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion coalib/parsing/StringProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def unescape(string):
:param string: The string to unescape.
"""
regex = r"\\(.)"
regex = r"\\(.)|\\$"

def replacement_function(match):
return match.group(1)
Expand Down
8 changes: 7 additions & 1 deletion coalib/tests/parsing/StringProcessingTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def set_up_unescape(self):
r"out1 'str1''str2''str3' out2",
r"",
r"out1 out2 out3",
self.bs,
r"",
self.bs]

def assertSearchForResultEqual(self,
Expand Down Expand Up @@ -1158,6 +1158,12 @@ def test_unescape(self):
for elem in compare:
self.assertEqual(elem[0], elem[1])

# Test unescape() for some special possible flaws.
def test_unescape_custom(self):
self.assertEqual(unescape("hello\\"), "hello")
self.assertEqual(unescape("te\st\\\\"), "test\\")
self.assertEqual(unescape("\\\\\\"), "\\")

def test_position_is_escaped(self):
test_string = r"\\\\\abcabccba###\\13q4ujsabbc\+'**'ac###.#.####-ba"
result_dict = {
Expand Down

0 comments on commit b5629cf

Please sign in to comment.