Skip to content

Commit

Permalink
cache_purge: don't escape HTML entities in URLs
Browse files Browse the repository at this point in the history
Ensures the exact cache key will match that which we have stored.

Closes #1350
  • Loading branch information
jacobbednarz committed Aug 7, 2023
1 parent efb9052 commit 3a6c2ce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changelog/1360.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
cloudflare: swap `encoding/json` for `github.com/goccy/go-json`
```

```release-note:bug
cache_purge: don't escape HTML entity values in URLs for cache keys
```
9 changes: 8 additions & 1 deletion zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,15 @@ func (api *API) PurgeCache(ctx context.Context, zoneID string, pcr PurgeCacheReq
//
// API reference: https://api.cloudflare.com/#zone-purge-individual-files-by-url-and-cache-tags
func (api *API) PurgeCacheContext(ctx context.Context, zoneID string, pcr PurgeCacheRequest) (PurgeCacheResponse, error) {
// manually build the payload to ensure we don't escape HTML entities to
// match their keys for purging.
payload, err := json.MarshalWithOption(pcr, json.DisableHTMLEscape())
if err != nil {
return PurgeCacheResponse{}, err
}

uri := fmt.Sprintf("/zones/%s/purge_cache", zoneID)
res, err := api.makeRequestContext(ctx, http.MethodPost, uri, pcr)
res, err := api.makeRequestContext(ctx, http.MethodPost, uri, payload)
if err != nil {
return PurgeCacheResponse{}, err
}
Expand Down

0 comments on commit 3a6c2ce

Please sign in to comment.