1

这有点奇怪(节点 repl v8.15.0):

let URL = require('url').URL
let {pathname} = new URL('https://my.domain.com/e30%3D/with%3F')
console.log(pathname) // logs '/e30%3D/with%3F' <-- this looks right

然后在我的 CloudFlare 工作人员中(使用service-worker-mock):

let URL = require('url').URL
let {pathname} = new URL('https://my.domain.com/e30%3D/with%3F')
console.log(pathname) // logs '/e30=/abc%21%3Fdef' <-- `=` unquoted in path? 

我猜它可能是一个不同的版本URL?反正我能控制吗?

4

1 回答 1

0

您对两个 URL 实现以相同方式解析的期望实际上是正确的,如果您打开检查器并运行第二个代码,它应该按照您期望的方式进行编码。不幸的是,正如Harris所指出的,Workers URL 的实现存在漏洞并且难以修复。我建议在您的代码中使用某种URL polyfill来正确编码 URL。

于 2020-01-19T23:24:30.063 回答