From ecbf17a9c0e76a2f4f06d2dc75b3a6ffa4652d3d Mon Sep 17 00:00:00 2001 From: Garvit Surana <251430630+garvitsurana271@users.noreply.github.com> Date: Mon, 23 Nov 2026 00:17:02 +0000 Subject: [PATCH] fix(boot-core): write a saved network's leading # as %23, so a name such as #Home is a network line and not a comment that no boot joins, the page never lists and Forget cannot remove (review W2) --- crates/stela-boot-core/src/wifi_saved.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/stela-boot-core/src/wifi_saved.rs b/crates/stela-boot-core/src/wifi_saved.rs index f752e656bf..97b73a7fb9 100644 --- a/crates/stela-boot-core/src/wifi_saved.rs +++ b/crates/stela-boot-core/src/wifi_saved.rs @@ -190,8 +190,11 @@ pub fn line(ssid: &[u8], secret: &[u8]) -> Vec { if n == 1 { line.push(b' '); } - for &byte in word { - if byte == b'%' || byte <= b' ' || byte >= 0x7f { + for (at, &byte) in word.iter().enumerate() { + // A line that starts with `#` reads as a comment, so a name's + // leading `#` is written as `%23`. + let comment = n == 0 && at == 0 && byte == b'#'; + if comment || byte == b'%' || byte <= b' ' || byte >= 0x7f { line.extend_from_slice(alloc::format!("%{byte:02X}").as_bytes()); } else { line.push(byte); @@ -214,6 +217,20 @@ mod tests { .collect() } + #[test] + fn a_name_that_starts_with_a_hash_is_saved_as_a_network_not_a_comment() { + let mut file = line(b"#Home", b"hunter2hunter2"); + assert_eq!(file, b"%23Home hunter2hunter2\n"); + let saved = parse(&file); + assert_eq!(saved_names(&saved), [&b"#Home"[..]]); + assert_eq!(names(&file), [b"#Home".to_vec()]); + // Forgotten again by its name. + assert!(without(&file, b"#Home").is_empty()); + // A `#` past the first byte, or in the secret, is written as it is. + assert_eq!(line(b"Home#2", b"pass#word1"), b"Home#2 pass#word1\n"); + wipe(&mut file); + } + #[test] fn an_unreadable_file_is_never_taken_for_an_empty_one() { let bytes = |text: &[u8]| Stored::Bytes(text.to_vec());