Skip to content

Commit

Permalink
types/model: make Name.Filepath substitute colons in host with ("%")
Browse files Browse the repository at this point in the history
This makes the filepath legal on all supported platforms.

Fixes #4088
  • Loading branch information
bmizerany committed May 2, 2024
1 parent 9164b01 commit 53241e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions types/model/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func ParseNameBare(s string) Name {
}

scheme, host, ok := strings.Cut(s, "://")
if ! ok {
if !ok {
host = scheme
}
n.Host = host
Expand Down Expand Up @@ -243,7 +243,7 @@ func (n Name) Filepath() string {
panic("illegal attempt to get filepath of invalid name")
}
return strings.ToLower(filepath.Join(
n.Host,
strings.Replace(n.Host, ":", "%", 1),
n.Namespace,
n.Model,
n.Tag,
Expand Down
15 changes: 12 additions & 3 deletions types/model/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestParseNameParts(t *testing.T) {
Model: "model",
Tag: "tag",
},
wantFilepath: filepath.Join("host:port", "namespace", "model", "tag"),
wantFilepath: filepath.Join("host%port", "namespace", "model", "tag"),
},
{
in: "host/namespace/model:tag",
Expand All @@ -47,7 +47,7 @@ func TestParseNameParts(t *testing.T) {
Model: "model",
Tag: "tag",
},
wantFilepath: filepath.Join("host:port", "namespace", "model", "tag"),
wantFilepath: filepath.Join("host%port", "namespace", "model", "tag"),
},
{
in: "host/namespace/model",
Expand All @@ -65,7 +65,7 @@ func TestParseNameParts(t *testing.T) {
Namespace: "namespace",
Model: "model",
},
wantFilepath: filepath.Join("host:port", "namespace", "model", "latest"),
wantFilepath: filepath.Join("host%port", "namespace", "model", "latest"),
},
{
in: "namespace/model",
Expand Down Expand Up @@ -127,6 +127,15 @@ func TestParseNameParts(t *testing.T) {
},
wantValidDigest: true,
},
{
in: "y.com:443/n/model",
want: Name{
Host: "y.com:443",
Namespace: "n",
Model: "model",
},
wantFilepath: filepath.Join("y.com%443", "n", "model", "latest"),
},
}

for _, tt := range cases {
Expand Down

0 comments on commit 53241e1

Please sign in to comment.