Skip to content

enumerator: normalize Linux USB VID/PID to uppercase#224

Merged
cmaglie merged 1 commit into
bugst:masterfrom
ultramcu:fix/enumerator-linux-vidpid-uppercase
May 26, 2026
Merged

enumerator: normalize Linux USB VID/PID to uppercase#224
cmaglie merged 1 commit into
bugst:masterfrom
ultramcu:fix/enumerator-linux-vidpid-uppercase

Conversation

@ultramcu
Copy link
Copy Markdown
Contributor

Problem

PortDetails.VID/PID are reported in different cases depending on the platform:

  • darwin formats them with %04X → uppercase (enumerator/usb_darwin.go)
  • Windows extracts them from device instance IDs that use uppercase hex (enumerator/usb_windows.go; the existing usb_windows_test.go fixtures assert uppercase like 0403/16C0)
  • Linux copied idVendor/idProduct straight from sysfs, which stores them lowercase

So the same physical device yields e.g. 1a86 on Linux but 1A86 on 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

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. Hardware-free; passes on Linux. gofmt/go vet clean. (Distinct from #108, which asks for VID/PID as a numeric type.)

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 cmaglie merged commit c91f207 into bugst:master May 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants