summaryrefslogtreecommitdiffstats
path: root/pym/portage/util/__init__.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-06-28 02:06:36 -0700
committerZac Medico <zmedico@gentoo.org>2011-06-28 02:06:36 -0700
commite63823dd8358f50559fa616313cdde3ceaf104ed (patch)
tree3d99c770fdcf27e6f519d160b1da737f46772ea6 /pym/portage/util/__init__.py
parent8ff8b0aad08d1381aeb410807881b46ba4bc7135 (diff)
downloadportage-e63823dd8358f50559fa616313cdde3ceaf104ed.tar.gz
portage-e63823dd8358f50559fa616313cdde3ceaf104ed.tar.bz2
portage-e63823dd8358f50559fa616313cdde3ceaf104ed.zip
varexpand: handle backslashes like more like bash
For backslash expansion, this function used to behave like 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. This will fix bash compatibility for the case reported in bug #365033.
Diffstat (limited to 'pym/portage/util/__init__.py')
-rw-r--r--pym/portage/util/__init__.py39
1 files changed, 13 insertions, 26 deletions
diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py
index 8c5352239..ece0806e2 100644
--- a/pym/portage/util/__init__.py
+++ b/pym/portage/util/__init__.py
@@ -683,37 +683,24 @@ def varexpand(mystring, mydict=None):
newstring=newstring+" "
pos=pos+1
elif (mystring[pos]=="\\"):
- #backslash expansion time
+ # For backslash expansion, this function used to behave like
+ # 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 genconfig() uses shlex
+ # to handle that earlier.
if (pos+1>=len(mystring)):
newstring=newstring+mystring[pos]
break
else:
- a=mystring[pos+1]
- pos=pos+2
- if a=='a':
- newstring=newstring+chr(0o07)
- elif a=='b':
- newstring=newstring+chr(0o10)
- elif a=='e':
- newstring=newstring+chr(0o33)
- elif (a=='f') or (a=='n'):
- newstring=newstring+chr(0o12)
- elif a=='r':
- newstring=newstring+chr(0o15)
- elif a=='t':
- newstring=newstring+chr(0o11)
- elif a=='v':
- newstring=newstring+chr(0o13)
- elif a in ('\'', '"'):
- # Quote removal is handled by shlex.
+ a = mystring[pos + 1]
+ pos = pos + 2
+ if a in ("\\", "$"):
+ newstring = newstring + a
+ else:
newstring = newstring + mystring[pos-2:pos]
- continue
- elif a!='\n':
- # Remove backslash only, as bash does. This takes care
- # of \\. Note that we don't handle quotes here since
- # quote removal is handled by shlex.
- newstring=newstring+mystring[pos-1:pos]
- continue
+ continue
elif (mystring[pos]=="$") and (mystring[pos-1]!="\\"):
pos=pos+1
if mystring[pos]=="{":