add another escape test case, fixup octal one (its \0XX instead of \0XXX)
authorMichael Vogt <michael.vogt@ubuntu.com>
Tue, 26 Jul 2011 09:10:47 +0000 (11:10 +0200)
committerMichael Vogt <michael.vogt@ubuntu.com>
Tue, 26 Jul 2011 09:10:47 +0000 (11:10 +0200)
apt-pkg/contrib/strutl.cc
apt-pkg/contrib/strutl.h
test/libapt/strutil_test.cc

index f9d8d7e..e998d74 100644 (file)
@@ -1242,10 +1242,10 @@ bool CheckDomainList(const string &Host,const string &List)
                                                                        /*}}}*/
 // ProcessEscapeSequences                                              /*{{{*/
 // ---------------------------------------------------------------------
-/*  */
+/* unescape (\0XX and \xXX) from a string */
 string DeEscapeString(string &input)
 {
-   char tmp[5];
+   char tmp[3];
    string::const_iterator it, escape_start;
    string output, octal, hex;
    for (it = input.begin(); it != input.end(); it++) 
@@ -1277,11 +1277,10 @@ string DeEscapeString(string &input)
       switch (*it)
       {
          case '0':
-            if (it + 3 <= input.end()) {
+            if (it + 2 <= input.end()) {
                tmp[0] = it[1];
                tmp[1] = it[2];
-               tmp[2] = it[3];
-               tmp[3] = 0;
+               tmp[2] = 0;
                output += (char)strtol(tmp, 0, 8);
                it += 2;
             }
index 43bbfe3..2a6bc19 100644 (file)
@@ -40,7 +40,7 @@ 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 (\0XXX and \xXX) from a string
+// unescape (\0XX and \xXX) from a string
 string DeEscapeString(string &input);
 
 string SizeToStr(double Bytes);
index 8d81a0c..af6eb2c 100644 (file)
@@ -36,5 +36,11 @@ int main(int argc,char *argv[])
    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;
 }