enumerator: normalize Linux USB VID/PID to uppercase#224
Merged
cmaglie merged 1 commit intoMay 26, 2026
Conversation
PortDetails.VID/PID were reported in different cases depending on the platform: the darwin backend formats them with %04X (usb_darwin.go) and the Windows backend extracts them from device IDs that use uppercase hex (usb_windows.go), but the Linux backend copied idVendor/idProduct straight from sysfs, which stores them lowercase. Code that compares or displays VID/PID across platforms (or matches against an uppercase table) got inconsistent results. Uppercase the VID and PID read from sysfs with strings.ToUpper, matching the darwin and Windows backends. The serial number's case is left untouched (it is not hex and may be case-significant). TestParseUSBSysFSVIDPIDUppercase writes lowercase idVendor=10c4/idProduct=ea60 plus a mixed-case serial into a temp sysfs-like dir and asserts parseUSBSysFS yields VID=10C4 PID=EA60 while preserving the serial's case.
cmaglie
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PortDetails.VID/PIDare reported in different cases depending on the platform:%04X→ uppercase (enumerator/usb_darwin.go)enumerator/usb_windows.go; the existingusb_windows_test.gofixtures assert uppercase like0403/16C0)idVendor/idProductstraight from sysfs, which stores them lowercaseSo the same physical device yields e.g.
1a86on Linux but1A86on macOS/Windows. Code that compares or displays VID/PID across platforms (or matches against an uppercase table) gets inconsistent results.Fix
Uppercase the VID and PID read from sysfs with
strings.ToUpper, matching the darwin and Windows backends. The serial number's case is left untouched (it is not hex and may be case-significant); no other field is changed.Test
TestParseUSBSysFSVIDPIDUppercasewrites lowercaseidVendor=10c4/idProduct=ea60plus a mixed-case serial into a temp sysfs-like dir and assertsparseUSBSysFSyieldsVID=10C4 PID=EA60while preserving the serial's case. Hardware-free; passes on Linux.gofmt/go vetclean. (Distinct from #108, which asks for VID/PID as a numeric type.)