Skip to content

Commit fb128af

Browse files
committed
[fix] Use 'null' as origin for non special URLs
1 parent fed6d9e commit fb128af

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ function Url(address, location, parser) {
371371
url.password = instruction[1] || '';
372372
}
373373

374-
url.origin = url.protocol && url.host && url.protocol !== 'file:'
374+
url.origin = url.protocol !== 'file:' && isSpecial(url.protocol) && url.host
375375
? url.protocol +'//'+ url.host
376376
: 'null';
377377

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

467-
url.origin = url.protocol && url.host && url.protocol !== 'file:'
467+
url.origin = url.protocol !== 'file:' && isSpecial(url.protocol) && url.host
468468
? url.protocol +'//'+ url.host
469469
: 'null';
470470

test/test.js

+7
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@ describe('url-parse', function () {
395395
assume(parsed.origin).equals('null');
396396
});
397397

398+
it('is null for non special URLs', function () {
399+
var o = parse('foo://example.com/pathname');
400+
assume(o.hostname).equals('example.com');
401+
assume(o.pathname).equals('/pathname');
402+
assume(o.origin).equals('null');
403+
});
404+
398405
it('removes default ports for http', function () {
399406
var o = parse('http://google.com:80/pathname');
400407
assume(o.origin).equals('http://google.com');

0 commit comments

Comments
 (0)