]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2598] Fixed and improved
authorFrancis Dupont <fdupont@isc.org>
Sat, 13 Jun 2026 09:31:10 +0000 (11:31 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 2 Jul 2026 07:46:22 +0000 (09:46 +0200)
src/lib/dhcp/classify.cc
src/lib/dhcp/tests/classify_unittest.cc

index 3a36c80e4fbfbdef24a995d07ac9a060fd25e70c..9617ec9da00e489a11550731f4e269c1f407a8d3 100644 (file)
@@ -14,8 +14,6 @@
 #include <boost/algorithm/string/constants.hpp>
 #include <boost/algorithm/string/split.hpp>
 
-#include <sstream>
-
 namespace isc {
 namespace dhcp {
 
@@ -164,20 +162,20 @@ const std::vector<bool> ClientClasses::CLIENT_CLASS_VALID_CHARACTERS = {
 
 std::string
 ClientClasses::escape(const std::string& name) {
-    std::stringstream ss;
+    std::string output;
     for (char const& c : name) {
-        unsigned u = static_cast<unsigned>(c);
+        uint8_t u = static_cast<uint8_t>(c);
         if ((u < 128) && CLIENT_CLASS_VALID_CHARACTERS[u]) {
-            ss << c;
+            output.push_back(c);
             if (c == CLIENT_CLASS_ESCAPE) {
-                ss << c;
+                output.push_back(CLIENT_CLASS_ESCAPE);
             }
         } else {
-            ss << CLIENT_CLASS_ESCAPE
-               << std::hex << std::setfill('0') << std::setw(2) << u;
+            output.push_back(CLIENT_CLASS_ESCAPE);
+            output.append(util::str::byteToHex(u));
         }
     }
-    return (ss.str());
+    return (output);
 }
 
 } // end of namespace dhcp
index fe499d2aebf498b81f75249b3506083973956c27..3464889be67a561c82f919979b9d441f6655deb7 100644 (file)
@@ -399,6 +399,9 @@ TEST(ClassifyTest, escape) {
         },
         {
             "\"foo\", \"bar\"", "%22foo%22%2c%20%22bar%22"
+        },
+        {
+            "\xeaoo\xe2" "ar", "%eaoo%e2ar"
         }
     };