Skip to content

Commit 0070cf0

Browse files
KhafraDevmetcoder95
authored andcommitted
fix: handle opaque origin in sameOrigin (nodejs#2053)
* fix: handle opaque origin in sameOrigin * fix: skip tsd on node 12
1 parent 606fcd1 commit 0070cf0

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

lib/fetch/util.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,9 @@ function tryUpgradeRequestToAPotentiallyTrustworthyURL (request) {
638638
*/
639639
function sameOrigin (A, B) {
640640
// 1. If A and B are the same opaque origin, then return true.
641-
// "opaque origin" is an internal value we cannot access, ignore.
641+
if (A.origin === B.origin && A.origin === 'null') {
642+
return true
643+
}
642644

643645
// 2. If A and B are both tuple origins and their schemes,
644646
// hosts, and port are identical, then return true.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@
4646
"build:wasm": "node build/wasm.js --docker",
4747
"lint": "standard | snazzy",
4848
"lint:fix": "standard --fix | snazzy",
49-
"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",
49+
"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",
5050
"test:cookies": "node scripts/verifyVersion 16 || tap test/cookie/*.js",
5151
"test:node-fetch": "node scripts/verifyVersion.js 16 || mocha test/node-fetch",
5252
"test:fetch": "node scripts/verifyVersion.js 16 || (npm run build:node && tap --expose-gc test/fetch/*.js && tap test/webidl/*.js)",
5353
"test:jest": "node scripts/verifyVersion.js 14 || jest",
5454
"test:tap": "tap test/*.js test/diagnostics-channel/*.js",
5555
"test:tdd": "tap test/*.js test/diagnostics-channel/*.js -w",
56-
"test:typescript": "tsd && tsc test/imports/undici-import.ts",
56+
"test:typescript": "node scripts/verifyVersion.js 14 || tsd",
5757
"test:websocket": "node scripts/verifyVersion.js 18 || tap test/websocket/*.js",
5858
"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)",
5959
"coverage": "nyc --reporter=text --reporter=html npm run test",

test/fetch/util.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ test('sameOrigin', (t) => {
111111
t.end()
112112
})
113113

114+
t.test('file:// urls', (t) => {
115+
// urls with opaque origins should return true
116+
117+
const a = new URL('file:///C:/undici')
118+
const b = new URL('file:///var/undici')
119+
120+
t.ok(util.sameOrigin(a, b))
121+
t.end()
122+
})
123+
114124
t.end()
115125
})
116126

0 commit comments

Comments
 (0)