Skip to content

Commit ca19fd8

Browse files
committed
Allow device names to start with a digit
This change ensures that device names starting with a digit are considered valid. This means that vendor.com/class=0 is a valid fully-qualified device name. Signed-off-by: Evan Lezar <[email protected]>
1 parent dc973e2 commit ca19fd8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pkg/cdi/qualified-device.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

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)