varexpand: remove escaped newline characters
authorZac Medico <zmedico@gentoo.org>
Fri, 1 Jul 2011 08:47:14 +0000 (01:47 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 1 Jul 2011 08:47:14 +0000 (01:47 -0700)
This fixes a regression reported in bug 365033, comment #14.

pym/portage/tests/util/test_varExpand.py
pym/portage/util/__init__.py

index 9dd488ea3a04bcf0536ef8102ab074dc1f700bcf..4af8f80c231de954b307e4c3d7eb70b2eae80c3d 100644 (file)
@@ -25,9 +25,10 @@ class VarExpandTestCase(TestCase):
                """
                We want to behave like bash does when expanding a variable
                assignment in a sourced file, in which case it performs
-               backslash removal for \\ and \$ but nothing more. Note that
-               we don't handle escaped quotes here, since genconfig() uses
-               shlex to handle that earlier.
+               backslash removal for \\ and \$ but nothing more. It also
+               removes escaped newline characters. Note that we don't
+               handle escaped quotes here, since genconfig() uses shlex
+               to handle that earlier.
                """
 
                varDict = {}
@@ -43,6 +44,7 @@ class VarExpandTestCase(TestCase):
                        ("\\n", "\\n"),
                        ("\\r", "\\r"),
                        ("\\t", "\\t"),
+                       ("\\\n", ""),
                        ("\\\"", "\\\""),
                        ("\\'", "\\'"),
                ]
index 85b2adaf9c2b6723329ef95d6788f31cf56b97d4..5468e28c9f2457b838c536647d20c1ec2159088e 100644 (file)
@@ -687,8 +687,9 @@ def varexpand(mystring, mydict=None):
                                # echo -e, but that's not needed for our purposes. We want to
                                # behave like bash does when expanding a variable assignment
                                # in a sourced file, in which case it performs backslash
-                               # removal for \\ and \$ but nothing more. Note that we don't
-                               # handle escaped quotes here, since getconfig() uses shlex
+                               # removal for \\ and \$ but nothing more. It also removes
+                               # escaped newline characters. Note that we don't handle
+                               # escaped quotes here, since getconfig() uses shlex
                                # to handle that earlier.
                                if (pos+1>=len(mystring)):
                                        newstring=newstring+mystring[pos]
@@ -698,6 +699,8 @@ def varexpand(mystring, mydict=None):
                                        pos = pos + 2
                                        if a in ("\\", "$"):
                                                newstring = newstring + a
+                                       elif a == "\n":
+                                               pass
                                        else:
                                                newstring = newstring + mystring[pos-2:pos]
                                        continue