1) Fixed URL segment separator issue. in GetPackageByName() preventing use on Microsoft Windows.#7
1) Fixed URL segment separator issue. in GetPackageByName() preventing use on Microsoft Windows.#7wvdvegt wants to merge 2 commits intoandygrunwald:masterfrom
Conversation
1) Fixed URL segment separator issue. in GetPackageByName() preventing use on Microsoft Windows.
Update packagist.go
| // GetPackageByName returns a package by a given name | ||
| func (c *PackagistClient) GetPackageByName(name string) (*PackagistPackage, *http.Response, error) { | ||
| u := fmt.Sprintf("%s/packages%s.json", c.url.String(), filepath.Clean("/"+name)) | ||
| u := fmt.Sprintf("%s/packages%s.json", c.url.String(), strings.Replace(filepath.Clean("/"+name), "\\", "/", -1)) |
There was a problem hiding this comment.
In #6 (comment) you pointed out that the issue might be the usage of filepath.Clean. What do you think about removing the filepath.Clean reference and replacing it with an URL fitting pattern? e.g. typical URL encoding?
Have a look at https://www.urlencoder.io/golang/ to check if one of those might be a good choice.
|
Hi |
|
Hi The following replacement appears to work on Windows (and using net/url): I'm not sure the first if statement is necessary as the packagist.org URL is probably hardcoded and not modifiable using a command line switch (so the url.Parse() can't fail. Personally I think this is indeed a better solution (properly building the url instead of stitching it together as a string) |
Should fix the issue.