Skip to content

Commit

Permalink
Escape path segments when constructing URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
justinas committed Jul 16, 2024
1 parent adce533 commit 00cc09e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/msgraph/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
Expand Down Expand Up @@ -227,8 +228,16 @@ func (c *Client) request(ctx context.Context, method string, uri string, payload
}

func (c *Client) endpointURI(segments ...string) *url.URL {
escapedSegments := make([]string, 0, cap(segments))
for _, s := range segments {
// Handling of slash vs escaped slash (%2F) in paths is ambiguous and inconsistent.
// See e.g.: https://stackoverflow.com/questions/1957115/is-a-slash-equivalent-to-an-encoded-slash-2f-in-the-path-portion-of-a
// We do not expect slashes to be needed within a single path segment,
// so we just remove slashes from each segment.
escapedSegments = append(escapedSegments, url.PathEscape(strings.ReplaceAll(s, "/", "")))
}
uri := c.baseURL
uri = uri.JoinPath(segments...)
uri = uri.JoinPath(escapedSegments...)
return uri
}

Expand Down

0 comments on commit 00cc09e

Please sign in to comment.