From: Arvin Schnell Date: Tue, 22 Mar 2022 09:43:13 +0000 (+0100) Subject: - fixed Pipe::escape X-Git-Tag: v0.10.0~7^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F700%2Fhead;p=thirdparty%2Fsnapper.git - fixed Pipe::escape --- diff --git a/dbus/DBusMessage.cc b/dbus/DBusMessage.cc index 2daf7fb5..0d1d8859 100644 --- a/dbus/DBusMessage.cc +++ b/dbus/DBusMessage.cc @@ -377,21 +377,21 @@ namespace DBus { string out; - for (string::const_iterator it = in.begin(); it != in.end(); ++it) + for (const char c : in) { - if (*it == '\\') + if (c == '\\') { out += "\\\\"; } - else if ((unsigned char)(*it) > 127) + else if ((unsigned char)(c) > 127) { char s[5]; - snprintf(s, 5, "\\x%02x", (unsigned char)(*it)); + snprintf(s, 5, "\\x%02x", (unsigned char)(c)); out += string(s); } else { - out += *it; + out += c; } } diff --git a/dbus/DBusPipe.cc b/dbus/DBusPipe.cc index df26324e..b332062e 100644 --- a/dbus/DBusPipe.cc +++ b/dbus/DBusPipe.cc @@ -89,10 +89,10 @@ namespace DBus { out += "\\\\"; } - else if (c <= ' ') + else if ((unsigned char)(c) <= ' ') { char s[5]; - snprintf(s, 5, "\\x%02x", c); + snprintf(s, 5, "\\x%02x", (unsigned char)(c)); out += string(s); } else diff --git a/testsuite/dbus-escape.cc b/testsuite/dbus-escape.cc index 038a7b2c..cbb1f037 100644 --- a/testsuite/dbus-escape.cc +++ b/testsuite/dbus-escape.cc @@ -41,10 +41,14 @@ BOOST_AUTO_TEST_CASE(hihi_unescape) BOOST_AUTO_TEST_CASE(pipe_escape) { BOOST_CHECK_EQUAL(Pipe::escape("hello world\n"), "hello\\x20world\\x0a"); + + BOOST_CHECK_EQUAL(Pipe::escape("ä"), "ä"); } BOOST_AUTO_TEST_CASE(pipe_unescape) { BOOST_CHECK_EQUAL(Pipe::unescape("hello\\x20world\\x0a"), "hello world\n"); + + BOOST_CHECK_EQUAL(Pipe::unescape("ä"), "ä"); }