fix: avoid calling splitString ""...

because it breaks evaluation on darwin with at least nix 2.18.

Evaluating `lib.splitString "" "foo"` throws the following:
`error: invalid regular expression ''`.

We could avoid that by using lib.stringToCharacters, but as
we are mapping over it anyway, lib.stringAsChars seems to be
an even better fit.

I tested the examples in hexEscapeUdevSymlinks docstring manually
in a nix repl.
This commit is contained in:
phaer authored and mergify[bot] committed 2024-10-23 19:46:38 +00:00
1 parent 4be2aadf13
commit 09a776702b
1 file changed
+4 -7
+4 -7
View File
@@ -105,15 +105,12 @@ let
hexEscapeUdevSymlink "all0these@char#acters+_are-allow.ed"
=> "all0these@char#acters+_are-allow.ed"
*/
hexEscapeUdevSymlink = with lib; let
hexEscapeUdevSymlink = let
allowedChars = "[0-9A-Za-z#+-.:=@_/]";
charToHex = c: toHexString (strings.charToInt c);
charToHex = c: lib.toHexString (lib.strings.charToInt c);
in
str: pipe str [
(splitString "")
(map (c: if match allowedChars c != null || c == "" then c else "\\x" + charToHex c))
concatStrings
];
lib.stringAsChars
(c: if lib.match allowedChars c != null || c == "" then c else "\\x" + charToHex c);
/* get the index an item in a list