From d3061af7b77c3a90ae4f2976594e0b6fb8a169e8 Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Tue, 22 Mar 2022 10:43:13 +0100 Subject: [PATCH] - fixed Pipe::escape --- dbus/DBusMessage.cc | 10 +++++----- dbus/DBusPipe.cc | 4 ++-- testsuite/dbus-escape.cc | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) 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("ä"), "ä"); } -- 2.47.3