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.
This commit is contained in:
alex authored and Alex Zenla committed 2026-09-26 20:52:15 -07:00
1 parent c898a1499c
commit c54a597917
1 file changed
+10
+10
View File
@@ -45,6 +45,10 @@ impl FromStr for BlsEntry {
let mut version: Option<String> = None;
let mut machine_id: Option<String> = 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();