Skip to content

Commit 3b39456

Browse files
authored
Merge pull request #70 from elezar/relax-device-name
Relax device name restriction
2 parents dc973e2 + 045438e commit 3b39456

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

pkg/cdi/qualified-device.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func ValidateVendorName(vendor string) error {
130130
}
131131
}
132132
if !isAlphaNumeric(rune(vendor[len(vendor)-1])) {
133-
return errors.Errorf("invalid vendor %q, should end with letter", vendor)
133+
return errors.Errorf("invalid vendor %q, should end with a letter or digit", vendor)
134134
}
135135

136136
return nil
@@ -158,7 +158,7 @@ func ValidateClassName(class string) error {
158158
}
159159
}
160160
if !isAlphaNumeric(rune(class[len(class)-1])) {
161-
return errors.Errorf("invalid class %q, should end with letter", class)
161+
return errors.Errorf("invalid class %q, should end with a letter or digit", class)
162162
}
163163
return nil
164164
}
@@ -172,8 +172,11 @@ func ValidateDeviceName(name string) error {
172172
if name == "" {
173173
return errors.Errorf("invalid (empty) device name")
174174
}
175-
if !isLetter(rune(name[0])) {
176-
return errors.Errorf("invalid name %q, should start with letter", name)
175+
if !isAlphaNumeric(rune(name[0])) {
176+
return errors.Errorf("invalid class %q, should start with a letter or digit", name)
177+
}
178+
if len(name) == 1 {
179+
return nil
177180
}
178181
for _, c := range string(name[1 : len(name)-1]) {
179182
switch {
@@ -185,7 +188,7 @@ func ValidateDeviceName(name string) error {
185188
}
186189
}
187190
if !isAlphaNumeric(rune(name[len(name)-1])) {
188-
return errors.Errorf("invalid name %q, should start with letter", name)
191+
return errors.Errorf("invalid name %q, should end with a letter or digit", name)
189192
}
190193
return nil
191194
}

pkg/cdi/qualified-device_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ func TestQualifiedName(t *testing.T) {
4040
name: "dev",
4141
isQualified: true,
4242
},
43+
{
44+
device: "vendor.com/class=0",
45+
vendor: "vendor.com",
46+
class: "class",
47+
name: "0",
48+
isQualified: true,
49+
},
4350
{
4451
device: "vendor1.com/class1=dev1",
4552
vendor: "vendor1.com",

0 commit comments

Comments
 (0)