ocilayout: narrow Windows drive path detection

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2026-04-27 10:19:01 +02:00
parent 14ef96b3b5
commit bf34a4cbed
2 changed files with 14 additions and 5 deletions
+4 -5
View File
@@ -1,6 +1,7 @@
package ocilayout
import (
"regexp"
"strings"
"github.com/distribution/reference"
@@ -59,10 +60,8 @@ func (r Ref) String() string {
return s
}
var windowsDrivePath = regexp.MustCompile(`^[A-Za-z]:[\\/]`)
func isWindowsDrivePath(path string, colon int) bool {
if colon != 1 || len(path) < 2 {
return false
}
c := path[0]
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')
return colon == 1 && windowsDrivePath.MatchString(path)
}
+10
View File
@@ -40,11 +40,21 @@ func TestParse(t *testing.T) {
path: "/path/to/oci/@/layout",
tag: "latest",
},
{
s: "oci-layout://a:1.3",
path: "a",
tag: "1.3",
},
{
s: `oci-layout://C:\path\to\oci\layout`,
path: `C:\path\to\oci\layout`,
tag: "latest",
},
{
s: `oci-layout://C:/path/to/oci/layout`,
path: `C:/path/to/oci/layout`,
tag: "latest",
},
{
s: `oci-layout://C:\path\to\oci\layout:1.3`,
path: `C:\path\to\oci\layout`,