Skip to content

Commit 4470d60

Browse files
authored
runtimevar/filevar: Support relative paths in URL openers via a host of '.' (#3666)
1 parent 797302a commit 4470d60

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

runtimevar/filevar/filevar.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ func (o *URLOpener) OpenVariableURL(ctx context.Context, u *url.URL) (*runtimeva
109109
return nil, fmt.Errorf("open variable %v: invalid query parameter %q", u, param)
110110
}
111111
path := u.Path
112-
if os.PathSeparator != '/' {
112+
// Hostname == "." means a relative path, so drop the leading "/".
113+
// Also drop the leading "/" on Windows.
114+
if u.Host == "." || os.PathSeparator != '/' {
113115
path = strings.TrimPrefix(path, "/")
114116
}
115117
return OpenVariable(filepath.FromSlash(path), decoder, &opts)

runtimevar/filevar/filevar_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ func TestOpenVariableURL(t *testing.T) {
243243
{"file://" + txtPath + "?decoder=string&wait=1m", false, false, "hello world!"},
244244
// Invalid wait.
245245
{"file://" + txtPath + "?decoder=string&wait=xx", true, false, nil},
246+
// Relative path using host="."; bucket is created but error at read time.
247+
{"file://./../.." + nonexistentPath, false, true, nil},
246248
}
247249

248250
for _, test := range tests {

0 commit comments

Comments
 (0)