@@ -35,8 +35,13 @@ import (
3535)
3636
3737const (
38+ // RepositoryNameTotalLengthMax is the maximum total number of characters in a repository name.
39+ RepositoryNameTotalLengthMax = 255
40+
3841 // NameTotalLengthMax is the maximum total number of characters in a repository name.
39- NameTotalLengthMax = 255
42+ //
43+ // Deprecated: use [RepositoryNameTotalLengthMax] instead.
44+ NameTotalLengthMax = RepositoryNameTotalLengthMax
4045)
4146
4247var (
5560 // ErrNameEmpty is returned for empty, invalid repository names.
5661 ErrNameEmpty = errors .New ("repository name must have at least one component" )
5762
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 )
6065
6166 // ErrNameNotCanonical is returned when a name is not canonical.
6267 ErrNameNotCanonical = errors .New ("repository name must be canonical" )
@@ -190,10 +195,6 @@ func Parse(s string) (Reference, error) {
190195 return nil , ErrReferenceInvalidFormat
191196 }
192197
193- if len (matches [1 ]) > NameTotalLengthMax {
194- return nil , ErrNameTooLong
195- }
196-
197198 var repo repository
198199
199200 nameMatch := anchoredNameRegexp .FindStringSubmatch (matches [1 ])
@@ -205,6 +206,10 @@ func Parse(s string) (Reference, error) {
205206 repo .path = matches [1 ]
206207 }
207208
209+ if len (repo .path ) > RepositoryNameTotalLengthMax {
210+ return nil , ErrNameTooLong
211+ }
212+
208213 ref := reference {
209214 namedRepository : repo ,
210215 tag : matches [2 ],
@@ -243,14 +248,15 @@ func ParseNamed(s string) (Named, error) {
243248// WithName returns a named object representing the given string. If the input
244249// is invalid ErrReferenceInvalidFormat will be returned.
245250func WithName (name string ) (Named , error ) {
246- if len (name ) > NameTotalLengthMax {
247- return nil , ErrNameTooLong
248- }
249-
250251 match := anchoredNameRegexp .FindStringSubmatch (name )
251252 if match == nil || len (match ) != 3 {
252253 return nil , ErrReferenceInvalidFormat
253254 }
255+
256+ if len (match [2 ]) > RepositoryNameTotalLengthMax {
257+ return nil , ErrNameTooLong
258+ }
259+
254260 return repository {
255261 domain : match [1 ],
256262 path : match [2 ],
0 commit comments