summaryrefslogtreecommitdiff
path: root/lib/strings.nix
diff options
context:
space:
mode:
authorMikael Voss <mvs@nyantec.com>2025-04-18 13:41:53 +0200
committerMikael Voss <mvs@nyantec.com>2025-04-18 13:41:53 +0200
commit487a002c6387b95fc65aeb4a056ef208cba7a72b (patch)
tree28a22db063088d35129bd21f892ced36f62505f4 /lib/strings.nix
parentalt-ergo: 2.6.0 -> 2.6.1 (diff)
downloadnixpkgs-487a002c6387b95fc65aeb4a056ef208cba7a72b.tar.gz
lib/strings: Zero‐pad hex digits in escapeC
lib.strings.escapeC produces single‐digit hexadecimal strings for character values ≤ 15, which results in an ambiguity. If the following character is a hex digit, it will be interpreted as being part of the escape sequence. systemd, which also relies on C‐style escape sequences, does not decode single‐digit sequences at all, even if unambiguous. Padding the hexadecimal string with "0" avoids this problem.
Diffstat (limited to 'lib/strings.nix')
-rw-r--r--lib/strings.nix6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index f8b01ec1ebc5..7142a156e393 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -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