@@ -35,8 +35,13 @@ import (
35
35
)
36
36
37
37
const (
38
+ // RepositoryNameTotalLengthMax is the maximum total number of characters in a repository name.
39
+ RepositoryNameTotalLengthMax = 255
40
+
38
41
// NameTotalLengthMax is the maximum total number of characters in a repository name.
39
- NameTotalLengthMax = 255
42
+ //
43
+ // Deprecated: use [RepositoryNameTotalLengthMax] instead.
44
+ NameTotalLengthMax = RepositoryNameTotalLengthMax
40
45
)
41
46
42
47
var (
55
60
// ErrNameEmpty is returned for empty, invalid repository names.
56
61
ErrNameEmpty = errors .New ("repository name must have at least one component" )
57
62
58
- // ErrNameTooLong is returned when a repository name is longer than NameTotalLengthMax .
59
- ErrNameTooLong = fmt .Errorf ("repository name must not be more than %v characters" , NameTotalLengthMax )
63
+ // ErrNameTooLong is returned when a repository name is longer than RepositoryNameTotalLengthMax .
64
+ ErrNameTooLong = fmt .Errorf ("repository name must not be more than %v characters" , RepositoryNameTotalLengthMax )
60
65
61
66
// ErrNameNotCanonical is returned when a name is not canonical.
62
67
ErrNameNotCanonical = errors .New ("repository name must be canonical" )
@@ -190,10 +195,6 @@ func Parse(s string) (Reference, error) {
190
195
return nil , ErrReferenceInvalidFormat
191
196
}
192
197
193
- if len (matches [1 ]) > NameTotalLengthMax {
194
- return nil , ErrNameTooLong
195
- }
196
-
197
198
var repo repository
198
199
199
200
nameMatch := anchoredNameRegexp .FindStringSubmatch (matches [1 ])
@@ -205,6 +206,10 @@ func Parse(s string) (Reference, error) {
205
206
repo .path = matches [1 ]
206
207
}
207
208
209
+ if len (repo .path ) > RepositoryNameTotalLengthMax {
210
+ return nil , ErrNameTooLong
211
+ }
212
+
208
213
ref := reference {
209
214
namedRepository : repo ,
210
215
tag : matches [2 ],
@@ -243,14 +248,15 @@ func ParseNamed(s string) (Named, error) {
243
248
// WithName returns a named object representing the given string. If the input
244
249
// is invalid ErrReferenceInvalidFormat will be returned.
245
250
func WithName (name string ) (Named , error ) {
246
- if len (name ) > NameTotalLengthMax {
247
- return nil , ErrNameTooLong
248
- }
249
-
250
251
match := anchoredNameRegexp .FindStringSubmatch (name )
251
252
if match == nil || len (match ) != 3 {
252
253
return nil , ErrReferenceInvalidFormat
253
254
}
255
+
256
+ if len (match [2 ]) > RepositoryNameTotalLengthMax {
257
+ return nil , ErrNameTooLong
258
+ }
259
+
254
260
return repository {
255
261
domain : match [1 ],
256
262
path : match [2 ],
0 commit comments