Skip to content

Commit

Permalink
Handle empty lines in hidutil output
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Feb 11, 2024
1 parent a59d12b commit 388c235
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ fn parse_hidutil_output(mut output: &str) -> Result<Vec<Device>> {
output = &output[line.len() + 1..];

while !output.is_empty() {
// skip over any leading newlines
if output.starts_with("\n") {
output = &output[1..];
continue;
}

let mut line_end = 0;

// parse the line into a map of header -> value using the header
Expand Down Expand Up @@ -297,4 +303,30 @@ UserDevice 1
]
);
}

#[test]
fn test_parse_hidutil_output_empty_line() {
let output = r#"Services:
VendorID ProductID LocationID UsagePage Usage RegistryID Transport Class
Devices:
VendorID ProductID Product Built-In
0x0 0x0 BTM (null)
"#;

let devices = parse_hidutil_output(output).unwrap();
assert_eq!(
devices,
vec![Device {
vendor_id: 0,
product_id: 0,
name: "BTM".to_owned()
}]
);
}
}

0 comments on commit 388c235

Please sign in to comment.