operator: escape dots in url (#2990)

This commit is contained in:
3u13r 2024-03-15 22:44:10 +01:00 committed by GitHub
parent c40e1a9bbd
commit 0b13c5bca9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -14,8 +14,8 @@ import (
)
var (
diskSourceRegex = regexp.MustCompile(`^https://www.googleapis.com/compute/v1/projects/([^/]+)/zones/([^/]+)/disks/([^/]+)$`)
computeAPIBase = regexp.MustCompile(`^https://www.googleapis.com/compute/v1/(.+)$`)
diskSourceRegex = regexp.MustCompile(`^https://www\.googleapis\.com/compute/v1/projects/([^/]+)/zones/([^/]+)/disks/([^/]+)$`)
computeAPIBase = regexp.MustCompile(`^https://www\.googleapis\.com/compute/v1/(.+)$`)
)
// diskSourceToDiskReq converts a disk source URI to a disk request.

View File

@ -36,6 +36,10 @@ func TestDiskSourceToDiskReq(t *testing.T) {
diskSource: "invalid://www.googleapis.com/compute/v1/projects/project/zones/zone/disks/disk",
wantErr: true,
},
"url dots in regex are escaped": {
diskSource: "https://wwwAgoogleapisAcom/compute/v1/projects/project/zones/zone/disks/disk",
wantErr: true,
},
}
for name, tc := range testCases {
@ -67,6 +71,10 @@ func TestURINormalize(t *testing.T) {
imageURI: "projects/project/global/images/image",
wantNormalized: "projects/project/global/images/image",
},
"url dots in regex are escaped": {
imageURI: "https://wwwAgoogleapisAcom/compute/v1/projects/project/global/images/image",
wantNormalized: "https://wwwAgoogleapisAcom/compute/v1/projects/project/global/images/image",
},
}
for name, tc := range testCases {