Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions file_uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ func FileURINew(path string) (*FileURI, error) {
uri := FileURI{
Scheme: u.Scheme,
Bucket: u.Host,
Path: u.Path,
}

if uri.Scheme == "" {
uri.Scheme = "file"
}
if uri.Scheme == "s3" && uri.Path != "" {
uri.Path = uri.Path[1:]
}
if uri.Path == "" && uri.Scheme == "s3" {
uri.Path = "/"
if u.RawPath != "" {
uri.Path = u.RawPath
} else {
uri.Path = u.EscapedPath()
}

return &uri, nil
Expand Down
39 changes: 39 additions & 0 deletions file_uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,43 @@ func TestURI(t *testing.T) {
if turi := uri.Join("new/file.txt"); turi.Path != "test/of/new/file.txt" {
t.Error("error join new/file.txt", turi.Path)
}

value = "test/of/test%2Fwith%2Fslashes.txt"
uri, err = FileURINew(value)
if err != nil {
t.Error("error parsing ", value)
}
if uri.Path != "test/of/test%2Fwith%2Fslashes.txt" || uri.Scheme != "file" || uri.Bucket != "" {
t.Error("error parsing ", value)
}
if uri.String() != "file://test/of/test%2Fwith%2Fslashes.txt" {
t.Error("roundtrip ", value, uri.String())
}

value = "test/of/test%2Fwith%2Fslashes and spaces.txt"
uri, err = FileURINew(value)
if err != nil {
t.Error("error parsing ", value)
}
if uri.Path != "test/of/test%2Fwith%2Fslashes and spaces.txt" || uri.Scheme != "file" || uri.Bucket != "" {
t.Error("error parsing ", value)
}
if uri.String() != "file://test/of/test%2Fwith%2Fslashes and spaces.txt" {
t.Error("roundtrip ", value, uri.String())
}

value = "s3://bucket/test/of/test%2Fwith%2Fslashes and spaces.txt"
uri, err = FileURINew(value)
if err != nil {
t.Error("error parsing ", value)
}
if uri.Path != "/test/of/test%2Fwith%2Fslashes and spaces.txt" {
t.Errorf("expected path %s; got %s", "/test/of/test%2Fwith%2Fslashes and spaces.txt", value)
}
if uri.Scheme != "s3" || uri.Bucket != "bucket" {
t.Error("error parsing ", value)
}
if uri.String() != "s3://bucket/test/of/test%2Fwith%2Fslashes and spaces.txt" {
t.Error("roundtrip ", value, uri.String())
}
}