]> git.saurik.com Git - apt.git/commitdiff
merged from lp:~mvo/apt/mvo
authorMichael Vogt <michael.vogt@ubuntu.com>
Tue, 26 Jul 2011 10:02:40 +0000 (12:02 +0200)
committerMichael Vogt <michael.vogt@ubuntu.com>
Tue, 26 Jul 2011 10:02:40 +0000 (12:02 +0200)
apt-pkg/contrib/cdromutl.cc
apt-pkg/contrib/strutl.cc
apt-pkg/contrib/strutl.h
debian/changelog
test/libapt/makefile
test/libapt/strutil_test.cc [new file with mode: 0644]

index 821e6d688e45b2fd083ffea530de738dd0101dbd..e25caf1a53aface16d4075fef1588e4ff60f7046 100644 (file)
@@ -258,7 +258,9 @@ string FindMountPointForDevice(const char *devnode)
                if(TokSplitString(' ', buf, out, 10))
                {
                   fclose(f);
-                  return string(out[1]);
+                  // unescape the \0XXX chars in the path
+                  string mount_point = out[1];
+                  return DeEscapeString(mount_point);
                }
             }
          }
index 072dda3ac3b1f74b76f403c4d79bbaffdc5fbbae..ab2da2d9af11a9b21ed9930b5ec76869754efef1 100644 (file)
@@ -1240,7 +1240,68 @@ bool CheckDomainList(const string &Host,const string &List)
    return false;
 }
                                                                        /*}}}*/
+// DeEscapeString - unescape (\0XX and \xXX) from a string             /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+string DeEscapeString(const string &input)
+{
+   char tmp[3];
+   string::const_iterator it, escape_start;
+   string output, octal, hex;
+   for (it = input.begin(); it != input.end(); it++) 
+   {
+      // just copy non-escape chars
+      if (*it != '\\')
+      {
+         output += *it;
+         continue;
+      }
 
+      // deal with double escape
+      if (*it == '\\' && 
+          (it + 1 < input.end()) &&  it[1] == '\\')
+      {
+         // copy
+         output += *it;
+         // advance iterator one step further
+         it += 1;
+         continue;
+      }
+        
+      // ensure we have a char to read
+      if (it + 1 == input.end())
+         continue;
+
+      // read it
+      it++;
+      switch (*it)
+      {
+         case '0':
+            if (it + 2 <= input.end()) {
+               tmp[0] = it[1];
+               tmp[1] = it[2];
+               tmp[2] = 0;
+               output += (char)strtol(tmp, 0, 8);
+               it += 2;
+            }
+            break;
+         case 'x':
+            if (it + 2 <= input.end()) {
+               tmp[0] = it[1];
+               tmp[1] = it[2];
+               tmp[2] = 0;
+               output += (char)strtol(tmp, 0, 16);
+               it += 2;
+            }
+            break;
+         default:
+            // FIXME: raise exception here?
+            break;
+      }
+   }
+   return output;
+}
+                                                                       /*}}}*/
 // URI::CopyFrom - Copy from an object                                 /*{{{*/
 // ---------------------------------------------------------------------
 /* This parses the URI into all of its components */
index 89cbf0370008f6c7db8c0909d159321811e6a66b..fba85cf94382d888d0aa11cbe46daf0d93774fe1 100644 (file)
@@ -39,6 +39,10 @@ bool ParseCWord(const char *&String,string &Res);
 string QuoteString(const string &Str,const char *Bad);
 string DeQuoteString(const string &Str);
 string DeQuoteString(string::const_iterator const &begin, string::const_iterator const &end);
+
+// unescape (\0XX and \xXX) from a string
+string DeEscapeString(const string &input);
+
 string SizeToStr(double Bytes);
 string TimeToStr(unsigned long Sec);
 string Base64Encode(const string &Str);
index 1eeb57ae76ebc833bd5bbbfee9cdd37afd7831df..6c2d2175425f7d80e3c7cbe5899d48f7839e21f1 100644 (file)
@@ -1,11 +1,19 @@
-apt (0.8.15.4) unstable; urgency=low
+apt (0.8.15.4) UNRELEASEDunstable; urgency=low
 
   [ David Miller ]
   * apt-pkg/contrib/sha1.cc:
     - fix illegally casts of on-stack buffer to a type requiring more
       alignment than it has resulting in segfaults on sparc (Closes: #634696)
 
- -- David Kalnischkies <kalnischkies@gmail.com>  Tue, 26 Jul 2011 08:26:53 +0200
+  [ Michael Vogt ]
+  * apt-pkg/contrib/cdromutl.cc:
+    - fix escape problem when looking for the mounted devices
+  * apt-pkg/contrib/strutl.{h,cc}, test/libapt/strutil_test.cc:
+    - add new DeEscapeString() similar to DeQuoteString but
+      unescape character escapes like \0XX and \xXX (plus added
+      test)
+  
+ -- Michael Vogt <mvo@debian.org>  Tue, 26 Jul 2011 11:58:27 +0200
 
 apt (0.8.15.3) unstable; urgency=low
 
index 50058262e748cfd65bab95439f22f5fea9286548..fec928ad202f0775089e2ded4461b4d90bdcbc07 100644 (file)
@@ -46,3 +46,9 @@ PROGRAM = GlobalError${BASENAME}
 SLIBS = -lapt-pkg
 SOURCE = globalerror_test.cc
 include $(PROGRAM_H)
+
+# test the strutils stuff
+PROGRAM = StrUtil${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = strutil_test.cc
+include $(PROGRAM_H)
diff --git a/test/libapt/strutil_test.cc b/test/libapt/strutil_test.cc
new file mode 100644 (file)
index 0000000..af6eb2c
--- /dev/null
@@ -0,0 +1,46 @@
+#include <apt-pkg/strutl.h>
+
+#include "assert.h"
+
+int main(int argc,char *argv[])
+{
+   string input, output, expected;
+
+   // no input
+   input = "foobar";
+   expected = "foobar";
+   output = DeEscapeString(input);
+   equals(output, expected);
+
+   // hex and octal
+   input = "foo\\040bar\\x0abaz";
+   expected = "foo bar\nbaz";
+   output = DeEscapeString(input);
+   equals(output, expected);
+
+   // at the end
+   input = "foo\\040";
+   expected = "foo ";
+   output = DeEscapeString(input);
+   equals(output, expected);
+
+   // double escape
+   input = "foo\\\\ x";
+   expected = "foo\\ x";
+   output = DeEscapeString(input);
+   equals(output, expected);
+
+   // double escape at the end
+   input = "\\\\foo\\\\";
+   expected = "\\foo\\";
+   output = DeEscapeString(input);
+   equals(output, expected);
+
+   // the string that we actually need it for
+   input = "/media/Ubuntu\\04011.04\\040amd64";
+   expected = "/media/Ubuntu 11.04 amd64";
+   output = DeEscapeString(input);
+   equals(output, expected);
+
+   return 0;
+}