Skip to content

Commit 2bae058

Browse files
committed
Parse: minor optimizations
- add early return for empty strings - skip lowercase-regex if the input is already lowercase Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 727f80d commit 2bae058

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

reference.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,14 @@ func splitDomain(name string) (string, string) {
228228
// _ "crypto/sha256"
229229
// )
230230
func Parse(s string) (Reference, error) {
231+
if s == "" {
232+
return nil, ErrNameEmpty
233+
}
234+
231235
matches := ReferenceRegexp.FindStringSubmatch(s)
232236
if matches == nil {
233-
if s == "" {
234-
return nil, ErrNameEmpty
235-
}
236-
if ReferenceRegexp.FindStringSubmatch(strings.ToLower(s)) != nil {
237+
if sl := strings.ToLower(s); sl != s && ReferenceRegexp.FindStringSubmatch(sl) != nil {
238+
// Succeeds when lower-casing, so input contains an invalid repository name.
237239
return nil, ErrNameContainsUppercase
238240
}
239241
return nil, ErrReferenceInvalidFormat

0 commit comments

Comments
 (0)