Skip to content

Commit 4e26f5d

Browse files
authored
Merge pull request #395 from huettern/fix/usb-port-id
fix: usb port parsing
2 parents 1058743 + a7c2674 commit 4e26f5d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

proxmox/config_qemu_usb.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (id UsbDeviceID) String() string {
325325
type UsbPortID string // regex: \d+-\d+
326326

327327
const (
328-
UsbPortID_Error_Invalid string = "invalid usb port id"
328+
UsbPortID_Error_Invalid string = "invalid usb port id. Expected expression of the form '<bus>-<port>(.<port>)*' where bus and port are integers"
329329
)
330330

331331
func (id UsbPortID) String() string {
@@ -340,8 +340,11 @@ func (id UsbPortID) Validate() error {
340340
if _, err := strconv.Atoi(idArray[0]); err != nil {
341341
return errors.New(UsbPortID_Error_Invalid)
342342
}
343-
if _, err := strconv.Atoi(idArray[1]); err != nil {
344-
return errors.New(UsbPortID_Error_Invalid)
343+
parts := strings.Split(idArray[1], ".")
344+
for _, part := range parts {
345+
if _, err := strconv.Atoi(part); err != nil {
346+
return errors.New(UsbPortID_Error_Invalid)
347+
}
345348
}
346349
return nil
347350
}

proxmox/config_qemu_usb_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ func Test_UsbPortID_Validate(t *testing.T) {
172172
}{
173173
{name: "Valid",
174174
input: "2-4"},
175+
{name: "Valid",
176+
input: "2-4.1"},
177+
{name: "Valid",
178+
input: "3-1.2.3.4.5.6.7.8.9"},
175179
// Invalid
176180
{name: "UsbPortID_Error_Invalid",
177181
input: "2-4-5",

0 commit comments

Comments
 (0)