File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -325,7 +325,7 @@ func (id UsbDeviceID) String() string {
325325type UsbPortID string // regex: \d+-\d+
326326
327327const (
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
331331func (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}
Original file line number Diff line number Diff 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" ,
You can’t perform that action at this time.
0 commit comments