Skip to content

Commit 80cccce

Browse files
joyeecheungFishrock123
authored andcommitted
url, test: including base argument in originFor
- Add tests to check if the `originFor` implementation for WHATWG url parsing is correnct. - Fix `originFor` by including a base as argument PR-URL: #10021 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1f11deb commit 80cccce

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎lib/internal/url.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,9 @@ Object.defineProperty(URLSearchParamsIteratorPrototype, Symbol.toStringTag, {
781781
configurable: true
782782
});
783783

784-
URL.originFor=function(url){
784+
URL.originFor=function(url,base){
785785
if(!(urlinstanceofURL))
786-
url=newURL(url);
786+
url=newURL(url,base);
787787
varorigin;
788788
constprotocol=url.protocol;
789789
switch(protocol){
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
5+
constURL=require('url').URL;
6+
constpath=require('path');
7+
constassert=require('assert');
8+
consttests=require(path.join(common.fixturesDir,'url-tests.json'));
9+
10+
for(consttestoftests){
11+
if(typeoftest==='string')
12+
continue;
13+
14+
if(test.origin){
15+
constorigin=URL.originFor(test.input,test.base);
16+
// Pass true to origin.toString() to enable unicode serialization.
17+
assert.strictEqual(origin.toString(true),test.origin);
18+
}
19+
}

0 commit comments

Comments
 (0)