Skip to content

Commit

Permalink
fix: handle opaque origin in sameOrigin (nodejs#2053)
Browse files Browse the repository at this point in the history
* fix: handle opaque origin in sameOrigin

* fix: skip tsd on node 12
  • Loading branch information
KhafraDev authored and metcoder95 committed Jul 21, 2023
1 parent 606fcd1 commit 0070cf0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,9 @@ function tryUpgradeRequestToAPotentiallyTrustworthyURL (request) {
*/
function sameOrigin (A, B) {
// 1. If A and B are the same opaque origin, then return true.
// "opaque origin" is an internal value we cannot access, ignore.
if (A.origin === B.origin && A.origin === 'null') {
return true
}

// 2. If A and B are both tuple origins and their schemes,
// hosts, and port are identical, then return true.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
"build:wasm": "node build/wasm.js --docker",
"lint": "standard | snazzy",
"lint:fix": "standard --fix | snazzy",
"test": "npm run test:tap && npm run test:node-fetch && npm run test:fetch && npm run test:cookies && npm run test:wpt && npm run test:websocket && npm run test:jest && tsd",
"test": "npm run test:tap && npm run test:node-fetch && npm run test:fetch && npm run test:cookies && npm run test:wpt && npm run test:websocket && npm run test:jest && npm run test:typescript",
"test:cookies": "node scripts/verifyVersion 16 || tap test/cookie/*.js",
"test:node-fetch": "node scripts/verifyVersion.js 16 || mocha test/node-fetch",
"test:fetch": "node scripts/verifyVersion.js 16 || (npm run build:node && tap --expose-gc test/fetch/*.js && tap test/webidl/*.js)",
"test:jest": "node scripts/verifyVersion.js 14 || jest",
"test:tap": "tap test/*.js test/diagnostics-channel/*.js",
"test:tdd": "tap test/*.js test/diagnostics-channel/*.js -w",
"test:typescript": "tsd && tsc test/imports/undici-import.ts",
"test:typescript": "node scripts/verifyVersion.js 14 || tsd",
"test:websocket": "node scripts/verifyVersion.js 18 || tap test/websocket/*.js",
"test:wpt": "node scripts/verifyVersion 18 || (node test/wpt/start-fetch.mjs && node test/wpt/start-FileAPI.mjs && node test/wpt/start-mimesniff.mjs && node test/wpt/start-xhr.mjs && node --no-warnings test/wpt/start-websockets.mjs)",
"coverage": "nyc --reporter=text --reporter=html npm run test",
Expand Down
10 changes: 10 additions & 0 deletions test/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ test('sameOrigin', (t) => {
t.end()
})

t.test('file:// urls', (t) => {
// urls with opaque origins should return true

const a = new URL('file:///C:/undici')
const b = new URL('file:///var/undici')

t.ok(util.sameOrigin(a, b))
t.end()
})

t.end()
})

Expand Down

0 comments on commit 0070cf0

Please sign in to comment.