mirror of
https://github.com/edera-dev/sprout.git
synced 2026-11-04 17:52:20 +00:00
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:
1 parent
c898a1499c
commit
c54a597917
1 file changed
+10
@@ -45,6 +45,10 @@ impl FromStr for BlsEntry {
|
|||||||
let mut version: Option<String> = None;
|
let mut version: Option<String> = None;
|
||||||
let mut machine_id: 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.
|
// Iterate over each line in the input and parse it.
|
||||||
for line in input.lines() {
|
for line in input.lines() {
|
||||||
let line = line.trim();
|
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"));
|
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]
|
#[test]
|
||||||
fn initrd_paths_normalises_slashes() {
|
fn initrd_paths_normalises_slashes() {
|
||||||
let entry: BlsEntry = "linux /vmlinuz\ninitrd /boot/initrd.img\n".parse().unwrap();
|
let entry: BlsEntry = "linux /vmlinuz\ninitrd /boot/initrd.img\n".parse().unwrap();
|
||||||
|
|||||||
Reference in new issue
Block a user