From 73c3f7c7ea0c8e9357554f9f258862a6a4b0b8d7 Mon Sep 17 00:00:00 2001 From: Daniel Jiang Date: Thu, 3 Dec 2020 12:53:04 +0800 Subject: [PATCH] Fix the pattern to match v2 catalog URI Signed-off-by: Daniel Jiang --- src/lib/patterns.go | 2 +- src/lib/patterns_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/lib/patterns.go b/src/lib/patterns.go index 1e210fbb8..743eac3c5 100644 --- a/src/lib/patterns.go +++ b/src/lib/patterns.go @@ -27,7 +27,7 @@ var ( // V2BlobUploadURLRe is the regular expression for matching the request to v2 handler to upload a blob, the upload uuid currently is not put into a group V2BlobUploadURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/blobs/uploads[/a-zA-Z0-9\-_\.=]*$`, RepositorySubexp, reference.NameRegexp.String())) // V2CatalogURLRe is the regular expression for mathing the request to v2 handler to list catalog - V2CatalogURLRe = regexp.MustCompile(`^/v2/_catalog$`) + V2CatalogURLRe = regexp.MustCompile(`^/v2/_catalog/?$`) ) // MatchManifestURLPattern checks whether the provided path matches the manifest URL pattern, diff --git a/src/lib/patterns_test.go b/src/lib/patterns_test.go index 5060f2307..20e698dac 100644 --- a/src/lib/patterns_test.go +++ b/src/lib/patterns_test.go @@ -66,3 +66,26 @@ func TestMatchBlobUploadURLPattern(t *testing.T) { assert.True(t, ok) assert.Equal(t, "library/hello-world", repository) } + +func TestMatchCatalogURLPattern(t *testing.T) { + cases := []struct { + url string + match bool + }{ + { + url: "/v2/_catalog", + match: true, + }, + { + url: "/v2/_catalog/", + match: true, + }, + { + url: "/v2/_catalog/xxx", + match: false, + }, + } + for _, c := range cases { + assert.Equal(t, c.match, len(V2CatalogURLRe.FindStringSubmatch(c.url)) == 1) + } +}