lib/strings: Zero‐pad hex digits in escapeC (#399722)

Changed files
+7 -3
lib
+5 -1
lib/strings.nix
···
:::
*/
-
escapeC = list: replaceStrings list (map (c: "\\x${toLower (lib.toHexString (charToInt c))}") list);
+
escapeC =
+
list:
+
replaceStrings list (
+
map (c: "\\x${fixedWidthString 2 "0" (toLower (lib.toHexString (charToInt c)))}") list
+
);
/**
Escape the `string` so it can be safely placed inside a URL
+2 -2
lib/tests/misc.nix
···
};
testEscapeC = {
-
expr = strings.escapeC [ " " ] "Hello World";
-
expected = "Hello\\x20World";
+
expr = strings.escapeC [ "\n" " " ] "Hello World\n";
+
expected = "Hello\\x20World\\x0a";
};
testEscapeURL = testAllTrue [