1 |
commit: 799c576de2afb31cea67cb2b186051bcdae29b1e |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Jul 1 08:47:14 2011 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Jul 1 08:47:14 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=799c576d |
7 |
|
8 |
varexpand: remove escaped newline characters |
9 |
|
10 |
This fixes a regression reported in bug 365033, comment #14. |
11 |
|
12 |
--- |
13 |
pym/portage/tests/util/test_varExpand.py | 8 +++++--- |
14 |
pym/portage/util/__init__.py | 7 +++++-- |
15 |
2 files changed, 10 insertions(+), 5 deletions(-) |
16 |
|
17 |
diff --git a/pym/portage/tests/util/test_varExpand.py b/pym/portage/tests/util/test_varExpand.py |
18 |
index 9dd488e..4af8f80 100644 |
19 |
--- a/pym/portage/tests/util/test_varExpand.py |
20 |
+++ b/pym/portage/tests/util/test_varExpand.py |
21 |
@@ -25,9 +25,10 @@ class VarExpandTestCase(TestCase): |
22 |
""" |
23 |
We want to behave like bash does when expanding a variable |
24 |
assignment in a sourced file, in which case it performs |
25 |
- backslash removal for \\ and \$ but nothing more. Note that |
26 |
- we don't handle escaped quotes here, since genconfig() uses |
27 |
- shlex to handle that earlier. |
28 |
+ backslash removal for \\ and \$ but nothing more. It also |
29 |
+ removes escaped newline characters. Note that we don't |
30 |
+ handle escaped quotes here, since genconfig() uses shlex |
31 |
+ to handle that earlier. |
32 |
""" |
33 |
|
34 |
varDict = {} |
35 |
@@ -43,6 +44,7 @@ class VarExpandTestCase(TestCase): |
36 |
("\\n", "\\n"), |
37 |
("\\r", "\\r"), |
38 |
("\\t", "\\t"), |
39 |
+ ("\\\n", ""), |
40 |
("\\\"", "\\\""), |
41 |
("\\'", "\\'"), |
42 |
] |
43 |
|
44 |
diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py |
45 |
index 85b2ada..5468e28 100644 |
46 |
--- a/pym/portage/util/__init__.py |
47 |
+++ b/pym/portage/util/__init__.py |
48 |
@@ -687,8 +687,9 @@ def varexpand(mystring, mydict=None): |
49 |
# echo -e, but that's not needed for our purposes. We want to |
50 |
# behave like bash does when expanding a variable assignment |
51 |
# in a sourced file, in which case it performs backslash |
52 |
- # removal for \\ and \$ but nothing more. Note that we don't |
53 |
- # handle escaped quotes here, since getconfig() uses shlex |
54 |
+ # removal for \\ and \$ but nothing more. It also removes |
55 |
+ # escaped newline characters. Note that we don't handle |
56 |
+ # escaped quotes here, since getconfig() uses shlex |
57 |
# to handle that earlier. |
58 |
if (pos+1>=len(mystring)): |
59 |
newstring=newstring+mystring[pos] |
60 |
@@ -698,6 +699,8 @@ def varexpand(mystring, mydict=None): |
61 |
pos = pos + 2 |
62 |
if a in ("\\", "$"): |
63 |
newstring = newstring + a |
64 |
+ elif a == "\n": |
65 |
+ pass |
66 |
else: |
67 |
newstring = newstring + mystring[pos-2:pos] |
68 |
continue |