mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
Fix relative path handling for file:// links
This commit is contained in:
@@ -5,6 +5,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -19,7 +22,18 @@ func ReadJSON(uri string, timeout time.Duration, target interface{}) error {
|
||||
case "http", "https":
|
||||
reader, err = newHTTPReader(u.String(), timeout)
|
||||
case "file":
|
||||
reader, err = newFileReader(u.Path)
|
||||
// if we have a file URI with relative path we need to expand it into an
|
||||
// absolute path, url.Parse doesn't support relative file paths
|
||||
if strings.HasPrefix(uri, "file:///") {
|
||||
reader, err = newFileReader(u.Path)
|
||||
} else {
|
||||
wd, e := os.Getwd()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
absolutePath := path.Join(wd, strings.TrimPrefix(uri, "file://"))
|
||||
reader, err = newFileReader(absolutePath)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("Unsupported URI scheme '%s' in '%s'", u.Scheme, u)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user