Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
114c932a
Unverified
Commit
114c932a
authored
Apr 27, 2024
by
Blake Mizerany
Committed by
GitHub
Apr 27, 2024
Browse files
types/model: allow _ as starter character in Name parts (#3991)
parent
7f7103de
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
10 deletions
+11
-10
types/model/name.go
types/model/name.go
+9
-9
types/model/name_test.go
types/model/name_test.go
+2
-1
No files found.
types/model/name.go
View file @
114c932a
...
@@ -109,19 +109,19 @@ type Name struct {
...
@@ -109,19 +109,19 @@ type Name struct {
// { model }
// { model }
// "@" { digest }
// "@" { digest }
// host:
// host:
// pattern: alphanum { alphanum | "-" | "_" | "." | ":" }*
// pattern:
{
alphanum
| "_" }
{ alphanum | "-" | "_" | "." | ":" }*
// length: [1, 350]
// length: [1, 350]
// namespace:
// namespace:
// pattern: alphanum { alphanum | "-" | "_" }*
// pattern:
{
alphanum
| "_" }
{ alphanum | "-" | "_" }*
// length: [1, 80]
// length: [1, 80]
// model:
// model:
// pattern: alphanum { alphanum | "-" | "_" | "." }*
// pattern:
{
alphanum
| "_" }
{ alphanum | "-" | "_" | "." }*
// length: [1, 80]
// length: [1, 80]
// tag:
// tag:
// pattern: alphanum { alphanum | "-" | "_" | "." }*
// pattern:
{
alphanum
| "_" }
{ alphanum | "-" | "_" | "." }*
// length: [1, 80]
// length: [1, 80]
// digest:
// digest:
// pattern: alphanum { alphanum | "-" | ":" }*
// pattern:
{
alphanum
| "_" }
{ alphanum | "-" | ":" }*
// length: [1, 80]
// length: [1, 80]
//
//
// Most users should use [ParseName] instead, unless need to support
// Most users should use [ParseName] instead, unless need to support
...
@@ -264,7 +264,7 @@ func isValidPart(kind partKind, s string) bool {
...
@@ -264,7 +264,7 @@ func isValidPart(kind partKind, s string) bool {
}
}
for
i
:=
range
s
{
for
i
:=
range
s
{
if
i
==
0
{
if
i
==
0
{
if
!
isAlphanumeric
(
s
[
i
])
{
if
!
isAlphanumeric
OrUnderscore
(
s
[
i
])
{
return
false
return
false
}
}
continue
continue
...
@@ -280,7 +280,7 @@ func isValidPart(kind partKind, s string) bool {
...
@@ -280,7 +280,7 @@ func isValidPart(kind partKind, s string) bool {
return
false
return
false
}
}
default
:
default
:
if
!
isAlphanumeric
(
s
[
i
])
{
if
!
isAlphanumeric
OrUnderscore
(
s
[
i
])
{
return
false
return
false
}
}
}
}
...
@@ -288,8 +288,8 @@ func isValidPart(kind partKind, s string) bool {
...
@@ -288,8 +288,8 @@ func isValidPart(kind partKind, s string) bool {
return
true
return
true
}
}
func
isAlphanumeric
(
c
byte
)
bool
{
func
isAlphanumeric
OrUnderscore
(
c
byte
)
bool
{
return
c
>=
'A'
&&
c
<=
'Z'
||
c
>=
'a'
&&
c
<=
'z'
||
c
>=
'0'
&&
c
<=
'9'
return
c
>=
'A'
&&
c
<=
'Z'
||
c
>=
'a'
&&
c
<=
'z'
||
c
>=
'0'
&&
c
<=
'9'
||
c
==
'_'
}
}
func
cutLast
(
s
,
sep
string
)
(
before
,
after
string
,
ok
bool
)
{
func
cutLast
(
s
,
sep
string
)
(
before
,
after
string
,
ok
bool
)
{
...
...
types/model/name_test.go
View file @
114c932a
...
@@ -103,6 +103,8 @@ func TestParseNameParts(t *testing.T) {
...
@@ -103,6 +103,8 @@ func TestParseNameParts(t *testing.T) {
var
testCases
=
map
[
string
]
bool
{
// name -> valid
var
testCases
=
map
[
string
]
bool
{
// name -> valid
""
:
false
,
""
:
false
,
"_why/_the/_lucky:_stiff"
:
true
,
// minimal
// minimal
"h/n/m:t@d"
:
true
,
"h/n/m:t@d"
:
true
,
...
@@ -167,7 +169,6 @@ func TestNameIsValid(t *testing.T) {
...
@@ -167,7 +169,6 @@ func TestNameIsValid(t *testing.T) {
var
numStringTests
int
var
numStringTests
int
for
s
,
want
:=
range
testCases
{
for
s
,
want
:=
range
testCases
{
n
:=
ParseNameBare
(
s
)
n
:=
ParseNameBare
(
s
)
t
.
Logf
(
"n: %#v"
,
n
)
got
:=
n
.
IsValid
()
got
:=
n
.
IsValid
()
if
got
!=
want
{
if
got
!=
want
{
t
.
Errorf
(
"parseName(%q).IsValid() = %v; want %v"
,
s
,
got
,
want
)
t
.
Errorf
(
"parseName(%q).IsValid() = %v; want %v"
,
s
,
got
,
want
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment