Merge pull request #3820 from crazy-max/ocilayout-fix-winpath-detection

ocilayout: narrow Windows drive path detection
This commit is contained in:
Tõnis Tiigi
2026-04-27 14:15:09 +02:00
committed by GitHub
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`,