From f968d7ee11e1c8171329ab9cec969919fbafa7ac Mon Sep 17 00:00:00 2001 From: Khafra Date: Sun, 9 Apr 2023 12:23:40 -0400 Subject: [PATCH] fix: handle opaque origin in sameOrigin (#2053) * fix: handle opaque origin in sameOrigin * fix: skip tsd on node 12 --- lib/fetch/util.js | 4 +++- package.json | 4 ++-- test/fetch/util.js | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/fetch/util.js b/lib/fetch/util.js index 4e44d9012af..23023262d14 100644 --- a/lib/fetch/util.js +++ b/lib/fetch/util.js @@ -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. diff --git a/package.json b/package.json index 636d52d9ce8..85f44d0614d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/fetch/util.js b/test/fetch/util.js index 3a6e63b6b2e..02b75bc7783 100644 --- a/test/fetch/util.js +++ b/test/fetch/util.js @@ -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() })