Skip to content

Commit

Permalink
[fix] Use 'null' as origin for non special URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Jul 24, 2021
1 parent fed6d9e commit fb128af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ function Url(address, location, parser) {
url.password = instruction[1] || '';
}

url.origin = url.protocol && url.host && url.protocol !== 'file:'
url.origin = url.protocol !== 'file:' && isSpecial(url.protocol) && url.host
? url.protocol +'//'+ url.host
: 'null';

Expand Down Expand Up @@ -464,7 +464,7 @@ function set(part, value, fn) {
if (ins[4]) url[ins[1]] = url[ins[1]].toLowerCase();
}

url.origin = url.protocol && url.host && url.protocol !== 'file:'
url.origin = url.protocol !== 'file:' && isSpecial(url.protocol) && url.host
? url.protocol +'//'+ url.host
: 'null';

Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ describe('url-parse', function () {
assume(parsed.origin).equals('null');
});

it('is null for non special URLs', function () {
var o = parse('foo://example.com/pathname');
assume(o.hostname).equals('example.com');
assume(o.pathname).equals('/pathname');
assume(o.origin).equals('null');
});

it('removes default ports for http', function () {
var o = parse('http://google.com:80/pathname');
assume(o.origin).equals('http://google.com');
Expand Down

0 comments on commit fb128af

Please sign in to comment.