This commit is contained in:
techknowlogick 2021-02-28 18:08:33 -05:00 committed by GitHub
parent 030646eea4
commit 47f6a4ec3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
947 changed files with 26119 additions and 7062 deletions

View file

@ -19,7 +19,9 @@ import (
"io/ioutil"
"log"
"net/http"
"net/url"
"path/filepath"
"runtime"
"strings"
"time"
)
@ -53,10 +55,30 @@ func LoadStrategy(path string, local, remote func(string) ([]byte, error)) func(
return remote
}
return func(pth string) ([]byte, error) {
upth, err := pathUnescape(strings.TrimPrefix(pth, `file://`))
upth, err := pathUnescape(pth)
if err != nil {
return nil, err
}
if strings.HasPrefix(pth, `file://`) {
if runtime.GOOS == "windows" {
// support for canonical file URIs on windows.
// Zero tolerance here for dodgy URIs.
u, _ := url.Parse(upth)
if u.Host != "" {
// assume UNC name (volume share)
// file://host/share/folder\... ==> \\host\share\path\folder
// NOTE: UNC port not yet supported
upth = strings.Join([]string{`\`, u.Host, u.Path}, `\`)
} else {
// file:///c:/folder/... ==> just remove the leading slash
upth = strings.TrimPrefix(upth, `file:///`)
}
} else {
upth = strings.TrimPrefix(upth, `file://`)
}
}
return local(filepath.FromSlash(upth))
}
}