workers-sdk
workers-sdk copied to clipboard
🐛 BUG: wrangler pages not correctly decoding URL to file path on redirect
Which Cloudflare product(s) does this pertain to?
Pages, Wrangler core, Miniflare
What version(s) of the tool(s) are you using?
3.52.0 [Wrangler]
What version of Node are you using?
20.7.0
What operating system and version are you using?
macOS Sonoma 14.3.1
Describe the Bug
Wrangler locally resolves precent-encoded URLs differently than CF. While CF behaves as expected, Wrangler locally fails at redirecting these URLs.
Observed behavior
Using wrangler pages dev for local development does not find files at paths
which require URL decoding and a redirect, e.g. when the pathname contains
%C3%A4 (ä).
# ok
curl -L http://localhost:8788/index.html
# ok (client encodes pathname as `/%C3%A4.txt`)
curl http://localhost:8788/ä.txt
# ok (client encodes pathname as `/%C3%B6`)
curl http://localhost:8788/ö
# ok
curl http://localhost:8788/%C3%A4.txt
# ok
curl http://localhost:8788/%C3%A4/
# [wrangler:inf] GET /%e4/ 404 Not Found
curl -L http://localhost:8788/%C3%A4/index.html
# [wrangler:inf] GET /%e4/ 404 Not Found
curl -L http://localhost:8788/%C3%A4
# [wrangler:inf] GET /%f6 404 Not Found
curl -L http://localhost:8788/ö.html
# [wrangler:inf] GET /%f6 404 Not Found
curl -L http://localhost:8788/ö/
# not found (expected)
curl http://localhost:8788/%E4.txt
Expected behavior
It should find the files matching the decoded pathnames.
# ok
curl -L http://localhost:8788/index.html
# ok (client encodes pathname as `/%C3%A4.txt`)
curl http://localhost:8788/ä.txt
# ok (client encodes pathname as `/%C3%B6`)
curl http://localhost:8788/ö
# ok
curl http://localhost:8788/%C3%A4.txt
# ok
curl http://localhost:8788/%C3%A4/
# ok after redirect to `http://localhost:8788/%C3%A4/`
curl -L http://localhost:8788/%C3%A4/index.html
# ok after redirect to `http://localhost:8788/%C3%A4/`
curl -L http://localhost:8788/%C3%A4
# ok after redirect to `http://localhost:8788/%C3%B6`
curl -L http://localhost:8788/ö.html
# ok after redirect to `http://localhost:8788/%C3%B6`
curl -L http://localhost:8788/ö/
# 4xx (graceful handling of malformed URIs)
curl http://localhost:8788/%E4.txt
Steps to reproduce
- Clone the repro repo.
- Install dependencies:
npm install - Start the server:
npx wrangler pages dev dist. - In a second terminal run the commands as illustrated for the observed behavior or any alternative to fetch these URLs.
Please provide a link to a minimal reproduction
https://github.com/valler/wrangler-pages-pathname-decode-repro-repo
Please provide any relevant error logs
No response