Codebase list golang-github-go-openapi-swag / v0.19.14
Merge pull request #56 from fredbi/fix-file-uri loader: fixed file uri scheme loader for windows Ivan Porto Carrero authored 3 years ago GitHub committed 3 years ago
2 changed file(s) with 24 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
3535 - funlen
3636 - gci
3737 - gocognit
38 - paralleltest
1818 "io/ioutil"
1919 "log"
2020 "net/http"
21 "net/url"
2122 "path/filepath"
23 "runtime"
2224 "strings"
2325 "time"
2426 )
5254 return remote
5355 }
5456 return func(pth string) ([]byte, error) {
55 upth, err := pathUnescape(strings.TrimPrefix(pth, `file://`))
57 upth, err := pathUnescape(pth)
5658 if err != nil {
5759 return nil, err
5860 }
61
62 if strings.HasPrefix(pth, `file://`) {
63 if runtime.GOOS == "windows" {
64 // support for canonical file URIs on windows.
65 // Zero tolerance here for dodgy URIs.
66 u, _ := url.Parse(upth)
67 if u.Host != "" {
68 // assume UNC name (volume share)
69 // file://host/share/folder\... ==> \\host\share\path\folder
70 // NOTE: UNC port not yet supported
71 upth = strings.Join([]string{`\`, u.Host, u.Path}, `\`)
72 } else {
73 // file:///c:/folder/... ==> just remove the leading slash
74 upth = strings.TrimPrefix(upth, `file:///`)
75 }
76 } else {
77 upth = strings.TrimPrefix(upth, `file://`)
78 }
79 }
80
5981 return local(filepath.FromSlash(upth))
6082 }
6183 }