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

This commit is contained in:
Norbert Melzer
2025-04-21 17:12:55 +02:00
committed by GitHub
2 changed files with 7 additions and 3 deletions
+5 -1
View File
@@ -998,7 +998,11 @@ rec {
:::
*/
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
View File
@@ -851,8 +851,8 @@ runTests {
};
testEscapeC = {
expr = strings.escapeC [ " " ] "Hello World";
expected = "Hello\\x20World";
expr = strings.escapeC [ "\n" " " ] "Hello World\n";
expected = "Hello\\x20World\\x0a";
};
testEscapeURL = testAllTrue [