Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions orb-connd/src/service/wifi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use color_eyre::Result;
use nom::{
branch::alt,
bytes::complete::tag,
combinator::{eof, fail, map},
combinator::{fail, map},
IResult,
};
use std::{
Expand Down Expand Up @@ -106,9 +106,6 @@ impl Credentials {
let (_, ()) = fail(input)?;
}

let (input, _) = tag(";")(input)?;
let (input, _) = eof(input)?;
Comment on lines -109 to -110
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure we want to allow arbitrary garbage at the end? Perhaps we only do opt(tag(";")) and keep eof in place?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reasoning here was that the parser takes only the first item anyway, so the garbage will not be processed. But I agree with you here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, reasoning is what @pophilpo said
as long as we can get the info we need it doesn't matter if whatever comes after is garbage

are there any bad cases you can think of that we will run into without opt(tag(";")) plus eof?


let auth_type = auth_type.unwrap_or_default();
let ssid = ssid.unwrap_or_default();
let hidden = hidden.unwrap_or_default();
Expand Down Expand Up @@ -163,6 +160,17 @@ mod tests {
assert!(!credentials.hidden);
}

#[test]
fn test_simple_permissive_semicolon() {
// single semicolon in the end
let input = "WIFI:T:WPA;S:mynetwork;P:mypass;";
let credentials = Credentials::parse(input).unwrap();
assert_eq!(credentials.auth, Auth::Wpa);
assert_eq!(credentials.ssid, "mynetwork");
assert_eq!(credentials.psk.unwrap(), "mypass");
assert!(!credentials.hidden);
}

#[test]
fn test_escaped() {
let input = r#"WIFI:S:\"foo\;bar\\baz\";;"#;
Expand Down Expand Up @@ -210,14 +218,23 @@ mod tests {

#[test]
fn test_duplicates() {
let input = "WIFI:H:true;P:mypass;T:WPA;S:mynetwork;P:mypass;;";
assert!(Credentials::parse(input).is_err());
let input =
"WIFI:H:true;P:mypass;T:WPA;S:mynetwork;P:myotherpass;S:myothernetwork;";
let credentials = Credentials::parse(input).unwrap();
assert_eq!(credentials.auth, Auth::Wpa);
assert_eq!(credentials.ssid, "mynetwork");
assert_eq!(credentials.psk.unwrap(), "mypass");
assert!(credentials.hidden);
}

#[test]
fn test_trailing_garbage() {
let input = "WIFI:T:WPA;S:mynetwork;P:mypass;;garbage";
assert!(Credentials::parse(input).is_err());
let credentials = Credentials::parse(input).unwrap();
assert_eq!(credentials.auth, Auth::Wpa);
assert_eq!(credentials.ssid, "mynetwork");
assert_eq!(credentials.psk.unwrap(), "mypass");
assert!(!credentials.hidden);
}

#[test]
Expand Down
Loading