Skip to content

Commit b44899b

Browse files
committed
Fix handling of Unicode serial numbers
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.
1 parent 290ab2c commit b44899b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/windows/enumerate.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,4 +570,8 @@ fn test_parsing_usb_port_information() {
570570
assert_eq!(info.serial_number, Some("385435603432".to_string()));
571571
#[cfg(feature = "usbportinfo-interface")]
572572
assert_eq!(info.interface, None);
573+
574+
let unicode_serial = r"USB\VID_F055&PID_9802\3854356β03432";
575+
let info = parse_usb_port_info(unicode_serial, None).unwrap();
576+
assert_eq!(info.serial_number.as_deref(), Some("3854356β03432"));
573577
}

0 commit comments

Comments
 (0)