Merge pull request #7 from dgolub/master
Fix canonical file URL detection on Windows.
diff --git a/reference.go b/reference.go
index ae04835..d4d2eca 100644
--- a/reference.go
+++ b/reference.go
@@ -30,6 +30,8 @@
"github.com/xeipuuv/gojsonpointer"
"net/url"
"path/filepath"
+ "runtime"
+ "strings"
)
const (
@@ -100,7 +102,18 @@
}
r.HasFileScheme = refUrl.Scheme == "file"
- r.HasFullFilePath = filepath.IsAbs(refUrl.Path)
+ if runtime.GOOS == "windows" {
+ // on Windows, a file URL may have an extra leading slash, and if it
+ // doesn't then its first component will be treated as the host by the
+ // Go runtime
+ if refUrl.Host == "" && strings.HasPrefix(refUrl.Path, "/") {
+ r.HasFullFilePath = filepath.IsAbs(refUrl.Path[1:])
+ } else {
+ r.HasFullFilePath = filepath.IsAbs(refUrl.Host + refUrl.Path)
+ }
+ } else {
+ r.HasFullFilePath = filepath.IsAbs(refUrl.Path)
+ }
// invalid json-pointer error means url has no json-pointer fragment. simply ignore error
r.referencePointer, _ = gojsonpointer.NewJsonPointer(refUrl.Fragment)