Skip to content

Commit

Permalink
docker/referece: add IsFullIdentifier
Browse files Browse the repository at this point in the history
containers/common/libimage is in need to check whether a given input
looks like a full image ID (i.e., a 64-byte hex string).  Since
compiling regexes has a negative impact on init- and run-time, let's
expose a function to check whether a given string matches the already
compiled regex in docker/reference.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
  • Loading branch information
vrothberg committed Feb 24, 2022
1 parent 306f204 commit 40befe3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docker/reference/regexp-additions.go
@@ -0,0 +1,6 @@
package reference

// Return true if the specified string fully matches `IdentifierRegexp`.
func IsFullIdentifier(s string) bool {
return anchoredIdentifierRegexp.MatchString(s)
}
3 changes: 3 additions & 0 deletions docker/reference/regexp_test.go
Expand Up @@ -545,6 +545,9 @@ func TestIdentifierRegexp(t *testing.T) {

for i := range fullCases {
checkRegexp(t, anchoredIdentifierRegexp, fullCases[i])
if IsFullIdentifier(fullCases[i].input) != fullCases[i].match {
t.Errorf("Expected match for %q to be %v", fullCases[i].input, fullCases[i].match)
}
}

for i := range shortCases {
Expand Down

0 comments on commit 40befe3

Please sign in to comment.