1package route53
2
3import (
4	"net/url"
5	"regexp"
6
7	"github.com/aws/aws-sdk-go/aws/awserr"
8	"github.com/aws/aws-sdk-go/aws/client"
9	"github.com/aws/aws-sdk-go/aws/request"
10	"github.com/aws/aws-sdk-go/private/protocol/restxml"
11)
12
13func init() {
14	initClient = func(c *client.Client) {
15		c.Handlers.Build.PushBack(sanitizeURL)
16	}
17
18	initRequest = func(r *request.Request) {
19		switch r.Operation.Name {
20		case opChangeResourceRecordSets:
21			r.Handlers.UnmarshalError.Remove(restxml.UnmarshalErrorHandler)
22			r.Handlers.UnmarshalError.PushBack(unmarshalChangeResourceRecordSetsError)
23		}
24	}
25}
26
27var reSanitizeURL = regexp.MustCompile(`\/%2F\w+%2F`)
28
29func sanitizeURL(r *request.Request) {
30	r.HTTPRequest.URL.RawPath =
31		reSanitizeURL.ReplaceAllString(r.HTTPRequest.URL.RawPath, "/")
32
33	// Update Path so that it reflects the cleaned RawPath
34	updated, err := url.Parse(r.HTTPRequest.URL.RawPath)
35	if err != nil {
36		r.Error = awserr.New(request.ErrCodeSerialization, "failed to clean Route53 URL", err)
37		return
38	}
39
40	// Take the updated path so the requests's URL Path has parity with RawPath.
41	r.HTTPRequest.URL.Path = updated.Path
42}
43