Skip to content

Commit

Permalink
Fix handling of Unicode serial numbers
Browse files Browse the repository at this point in the history
Rust str are indexed by byte, so doing .take().count()
is incorrect since Unicode values are often multiple
bytes. This fixes it and adds tests for the edge
cases.
  • Loading branch information
RossSmyth committed Jul 26, 2024
1 parent 290ab2c commit b44899b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/windows/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,8 @@ fn test_parsing_usb_port_information() {
assert_eq!(info.serial_number, Some("385435603432".to_string()));
#[cfg(feature = "usbportinfo-interface")]
assert_eq!(info.interface, None);

let unicode_serial = r"USB\VID_F055&PID_9802\3854356β03432";
let info = parse_usb_port_info(unicode_serial, None).unwrap();
assert_eq!(info.serial_number.as_deref(), Some("3854356β03432"));
}

0 comments on commit b44899b

Please sign in to comment.