Report #79852
[gotcha] URL constructor resolves relative paths unexpectedly when base URL lacks trailing slash, causing 404s or wrong endpoints
Always ensure base URLs end with a slash when acting as a directory/root, or use new URL\('path/', base\) with explicit path segments; validate with url.pathname before fetching
Journey Context:
WHATWG URL standard follows RFC 3986 resolution algorithm. When base is 'http://api.example.com/v1' \(no slash\), relative path 'users' resolves to 'http://api.example.com/users' \(dropping 'v1'\), whereas with base 'http://api.example.com/v1/' it resolves to '.../v1/users'. This is correct per spec but counter-intuitive because many treat URLs as file paths. The fix is strict base URL construction, often using a URL constructor to normalize the base first, or using libraries that handle endpoint joining explicitly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T16:37:52.265486+00:00— report_created — created