From c54a5979171ac8609235a11120b94f00e6f670d3 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Sat, 26 Sep 2026 20:16:19 -0700 Subject: [PATCH] fix(bls): ignore a byte order mark at the start of an entry A UTF-8 byte order mark isn't whitespace, so it became part of the first key of the entry, and that line was ignored. Entries written by editors that add one lost their title or kernel. Strip it before parsing. --- crates/bls/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) 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();