Fix a bug in command line option parsing code
authorNikos Skalkotos <skalkoto@grnet.gr>
Tue, 29 Nov 2011 12:30:46 +0000 (14:30 +0200)
committerIustin Pop <iustin@google.com>
Wed, 30 Nov 2011 09:37:06 +0000 (10:37 +0100)
Fix bug affecting command line options of "keyval" type. Although
escaping commands with \ is supported, it is is not applied to the
input recursively.

Signed-off-by: Nikos Skalkotos <skalkoto@grnet.gr>
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/utils/text.py

index e95c537..8aa39f5 100644 (file)
@@ -345,10 +345,12 @@ def UnescapeAndSplit(text, sep=","):
       num_b = len(e1) - len(e1.rstrip("\\"))
       if num_b % 2 == 1 and slist:
         e2 = slist.pop(0)
-        # here the backslashes remain (all), and will be reduced in
-        # the next step
-        rlist.append(e1 + sep + e2)
+        # Merge the two elements and push the result back to the source list for
+        # revisiting. If e2 ended with backslashes, further merging may need to
+        # be done.
+        slist.insert(0, e1 + sep + e2)
         continue
+    # here the backslashes remain (all), and will be reduced in the next step
     rlist.append(e1)
   # finally, replace backslash-something with something
   rlist = [re.sub(r"\\(.)", r"\1", v) for v in rlist]