]> git.saurik.com Git - apt.git/commitdiff
encode UTF-8 characters correctly in QuoteString
authorDavid Kalnischkies <david@kalnischkies.de>
Wed, 4 Nov 2015 22:38:40 +0000 (23:38 +0100)
committerDavid Kalnischkies <david@kalnischkies.de>
Thu, 5 Nov 2015 11:21:33 +0000 (12:21 +0100)
Limit the field length to a char to avoid bogus FF for
utf-8 characters with the default length.

Closes: 799123
apt-pkg/contrib/strutl.cc
test/libapt/strutil_test.cc

index 05624f7fba8a6f4fea0fd2d19ee92f871d97756a..396cb7898c0e5dc26f31bbbbe030aa4c7cb90ca9 100644 (file)
@@ -331,7 +331,7 @@ string QuoteString(const string &Str, const char *Bad)
          *I == 0x25 || // percent '%' char
          *I <= 0x20 || *I >= 0x7F) // control chars
       {
-        ioprintf(Res,"%%%02x",(int)*I);
+        ioprintf(Res, "%%%02hhx", *I);
       }
       else
         Res << *I;
index 23dc08727a3edaa1d991e50593df9aa2bc4bca4d..8947aea596aeececda261aea6714e46cf7eae2fb 100644 (file)
@@ -235,3 +235,14 @@ TEST(StrUtilTest,ReadMessages)
    ReadMessagesTestWithNewLine("\n\n", "ab");
    ReadMessagesTestWithNewLine("\r\n\r\n", "ab");
 }
+TEST(StrUtilTest,QuoteString)
+{
+   EXPECT_EQ("", QuoteString("", ""));
+   EXPECT_EQ("K%c3%b6ln", QuoteString("Köln", ""));
+   EXPECT_EQ("Köln", DeQuoteString(QuoteString("Köln", "")));
+   EXPECT_EQ("Köln", DeQuoteString(DeQuoteString(QuoteString(QuoteString("Köln", ""), ""))));
+   EXPECT_EQ("~-_$#|u%c3%a4%c3%b6%c5%a6%e2%84%a2%e2%85%9e%c2%b1%c3%86%e1%ba%9e%c2%aa%c3%9f", QuoteString("~-_$#|uäöŦ™⅞±Æẞªß", ""));
+   EXPECT_EQ("~-_$#|uäöŦ™⅞±Æẞªß", DeQuoteString(QuoteString("~-_$#|uäöŦ™⅞±Æẞªß", "")));
+   EXPECT_EQ("%45ltvill%65%2d%45rbach", QuoteString("Eltville-Erbach", "E-Ae"));
+   EXPECT_EQ("Eltville-Erbach", DeQuoteString(QuoteString("Eltville-Erbach", "")));
+}