From b44899b5bee3e6aa32bf1f36b8eea358f1c21c34 Mon Sep 17 00:00:00 2001 From: Ross Smyth <18294397+RossSmyth@users.noreply.github.com> Date: Thu, 25 Jul 2024 23:04:47 -0400 Subject: [PATCH] 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. --- src/windows/enumerate.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/windows/enumerate.rs b/src/windows/enumerate.rs index 315cc89b..2cb2d767 100644 --- a/src/windows/enumerate.rs +++ b/src/windows/enumerate.rs @@ -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")); }