mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 21:13:28 +01:00
disko: fix improper handling of whitespace
Fixes #130 This should fix pretty much all cases where spaces or other special characters would break disko due to improper quoting. I searched for all instances of '.label', '.device' and '.name', so I believe I caught whatever I could. In some cases I changed single quotes to double quotes for consistency. I know we don't usually fix bugs in the legacy table type, but it was so easy I couldn't resist.
This commit is contained in:
1 parent
78d685c123
commit
ca47da60e5
19 files changed
+114
-73
No files matched your search
+34
-1
@@ -82,6 +82,39 @@ let
|
||||
${dev} seems not to be a supported disk format. Please add this to disko in https://github.com/nix-community/disko/blob/master/lib/default.nix
|
||||
'';
|
||||
|
||||
/* Escape a string as required to be used in udev symlinks
|
||||
|
||||
The allowed characters are "0-9A-Za-z#+-.:=@_/", valid UTF-8 character sequences, and "\x00" hex encoding.
|
||||
Everything else is escaped as "\xXX" where XX is the hex value of the character.
|
||||
|
||||
The source of truth for the list of allowed characters is the udev documentation:
|
||||
https://www.freedesktop.org/software/systemd/man/latest/udev.html#SYMLINK1
|
||||
|
||||
This function is implemented as a best effort. It is not guaranteed to be 100% in line
|
||||
with the udev implementation, and we hope that you're not crazy enough to try to break it.
|
||||
|
||||
hexEscapeUdevSymlink :: str -> str
|
||||
|
||||
Example:
|
||||
hexEscapeUdevSymlink "Boot data partition"
|
||||
=> "Boot\x20data\x20partition"
|
||||
|
||||
hexEscapeUdevSymlink "Even(crazier)par&titi^onName"
|
||||
=> "Even\x28crazier\x29par\x26titi\x5EonName"
|
||||
|
||||
hexEscapeUdevSymlink "all0these@char#acters+_are-allow.ed"
|
||||
=> "all0these@char#acters+_are-allow.ed"
|
||||
*/
|
||||
hexEscapeUdevSymlink = with lib; let
|
||||
allowedChars = "[0-9A-Za-z#+-.:=@_/]";
|
||||
charToHex = c: toHexString (strings.charToInt c);
|
||||
in
|
||||
str: pipe str [
|
||||
(splitString "")
|
||||
(map (c: if match allowedChars c != null || c == "" then c else "\\x" + charToHex c))
|
||||
concatStrings
|
||||
];
|
||||
|
||||
/* get the index an item in a list
|
||||
|
||||
indexOf :: (a -> bool) -> [a] -> int -> int
|
||||
@@ -92,7 +125,7 @@ let
|
||||
|
||||
indexOf (x: x == "x") [ 1 2 3 ] 0
|
||||
=> 0
|
||||
*/
|
||||
*/
|
||||
indexOf = f: list: fallback:
|
||||
let
|
||||
iter = index: list:
|
||||
|
||||
Reference in new issue
Block a user