Skip to content

Commit 56cff07

Browse files
authored
Merge pull request #26 from thaJeztah/optimize_parse
2 parents 727f80d + 2bae058 commit 56cff07

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)