From 006e32cf2d01ff103d6c5c76e3189b4a54ec028d Mon Sep 17 00:00:00 2001 From: vmenge Date: Mon, 5 Jan 2026 20:29:07 +0100 Subject: [PATCH] chore(connd): more permissive wifi qr parsing --- orb-connd/src/service/wifi.rs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/orb-connd/src/service/wifi.rs b/orb-connd/src/service/wifi.rs index 522ea955..1e760fd9 100644 --- a/orb-connd/src/service/wifi.rs +++ b/orb-connd/src/service/wifi.rs @@ -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::{ @@ -106,9 +106,6 @@ impl Credentials { let (_, ()) = fail(input)?; } - let (input, _) = tag(";")(input)?; - let (input, _) = eof(input)?; - let auth_type = auth_type.unwrap_or_default(); let ssid = ssid.unwrap_or_default(); let hidden = hidden.unwrap_or_default(); @@ -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\";;"#; @@ -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]