diff --git a/crates/bls/src/lib.rs b/crates/bls/src/lib.rs index 97c97eb..f41391a 100644 --- a/crates/bls/src/lib.rs +++ b/crates/bls/src/lib.rs @@ -45,6 +45,10 @@ impl FromStr for BlsEntry { let mut version: Option = None; let mut machine_id: Option = None; + // Some editors write a UTF-8 byte order mark at the start of the file. + // It isn't whitespace, so it would otherwise be part of the first key. + let input = input.strip_prefix('\u{feff}').unwrap_or(input); + // Iterate over each line in the input and parse it. for line in input.lines() { let line = line.trim(); @@ -586,6 +590,12 @@ efi /EFI/fedora/shimx64.efi assert_eq!(entry.options().as_deref(), Some("root=/dev/sda1 ro quiet")); } + #[test] + fn parse_ignores_byte_order_mark() { + let entry: BlsEntry = "\u{feff}title Linux\nlinux /vmlinuz\n".parse().unwrap(); + assert_eq!(entry.title().as_deref(), Some("Linux")); + } + #[test] fn initrd_paths_normalises_slashes() { let entry: BlsEntry = "linux /vmlinuz\ninitrd /boot/initrd.img\n".parse().unwrap();