Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL components are not urlencoded, resulting in API failures for objects with certain names #14

Closed
alienth opened this issue Jun 29, 2016 · 4 comments · Fixed by #106
Closed

Comments

@alienth
Copy link
Contributor

alienth commented Jun 29, 2016

I have a cache condition with a name containing a character which needs to be urlencoded. (ex: a text/html condition). When I execute the following code which simply lists and tries to delete conditions which are found, it will fail:

        existingCacheSettings, err := client.ListCacheSettings(&fastly.ListCacheSettingsInput{Service: "abcd", Version: 10})
        for _, setting := range existingCacheSettings {
                err := client.DeleteCacheSetting(&fastly.DeleteCacheSettingInput{Service: "abcd", Name: setting.Name, Version: 10})
                if err != nil {
                        return err
                }
        }

The reason it is failing is because it ends up calling the following URL:

/service/abcd/version/10/condition/text/html

(note the unescaped forward-slash)

Any parameters which go into forming an API call URL should be urlescaped to prevent issues such as this. These object names are perfectly valid from Fastly's POV, but will cause go-fastly to malfunction.

I tried to address this in go-fastly by wrapping all URL components which could contain these characters in an escape method from net/url. Unfortunately, name components in the Fastly API may contain not only forward slashes but also whitespace, and net/url has no method to deal with both possible cases. Fixing this in go-fastly may require that we do a bit of a hacky strings.Replace().

@alienth alienth changed the title URL params are not urlencoded, resulting in API failures for objects with certain names URL components are not urlencoded, resulting in API failures for objects with certain names Jun 29, 2016
@alienth
Copy link
Contributor Author

alienth commented Jun 29, 2016

Bit of a stretch, but I've submitted a case to net/url to see if this type of escaping functionality can be supported: golang/go#16207

@alienth
Copy link
Contributor Author

alienth commented Jun 29, 2016

For now I think the best option avail is to write a small function which calls url.Parse() on URL components, and also encodes the forward-slashes. Started work on it this evening. I'll plan on sending a PR tomorrow.

@sethvargo
Copy link
Contributor

Looks like go 1.8 might fix this: golang/go@7e2bf95

kf6nux pushed a commit to kf6nux/go-fastly that referenced this issue Feb 8, 2017
@msuterski
Copy link
Contributor

msuterski commented Jul 13, 2017

Did this ever get fixed (in go 1.8)?

I run into similar problem in Terraform 0.9.4 with conditions that included / in names.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants