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)
This commit is contained in:
1 parent
20a5f5c45f
commit
ecbf17a9c0
1 file changed
+19
-2
@@ -190,8 +190,11 @@ pub fn line(ssid: &[u8], secret: &[u8]) -> Vec<u8> {
|
||||
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());
|
||||
|
||||
Reference in new issue
Block a user