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

Only undo '.' escaping in field names. #12

Merged
merged 1 commit into from
Jun 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,17 @@ func (c *Client) RequestForm(verb, p string, i interface{}, ro *RequestOptions)
}
ro.Headers["Content-Type"] = "application/x-www-form-urlencoded"

// There is a super-jank implementation in the form library where fields with
// a "dot" are replaced with "/.". That is then URL encoded and Fastly just
// dies. We fix that here.
body := strings.Replace(values.Encode(), "%5C.", ".", -1)
// Field names containing '.'s are replaced with '\.' in the form library.
// Since the Fastly API relies upon field names with periods, such as
// general.default_ttl, we must undo form's replace here.
for k, v := range values {
if strings.Contains(k, "\\.") {
newkey := strings.Replace(k, "\\.", ".", -1)
delete(values, k)
values[newkey] = v
}
}
body := values.Encode()

ro.Body = strings.NewReader(body)
ro.BodyLength = int64(len(body))
Expand Down