Skip to content

Commit

Permalink
fix: correctly match patterns containing "@" character
Browse files Browse the repository at this point in the history
refs inlinemanual/player#920
  • Loading branch information
fczbkk committed Mar 17, 2017
1 parent ea8e5d1 commit cb3b3fa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const split_re = new RegExp(
'^' + // beginning
'([a-z]+|\\*)*' + // (1) scheme
'://' + // scheme separator
'(.+@)*' + // (2) username and/or password
'([^\\/\\#\\?]+@)*' + // (2) username and/or password
'([\\w\\*\\.\\-]+)*' + // (3) host
'(\\:\\d+)*' + // (4) port number
'(/([^\\?\\#]*))*' + // (5) path, (6) excluding slash
Expand Down
30 changes: 30 additions & 0 deletions test/pattern.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,36 @@ describe('Pattern', function() {
expect(result.fragment).toEqual('jjj');
});

it('should allow @ in URL', function () {
const result = pattern.split('http://aaa.bbb/ccc@ddd');
expect(result.host).toEqual('aaa.bbb');
expect(result.path).toEqual('ccc@ddd');
});

it('should allow username and password and @ in URL', function () {
const result = pattern.split('http://aaa:bbb@ccc.ddd/eee@fff');
expect(result.host).toEqual('ccc.ddd');
expect(result.path).toEqual('eee@fff');
});

it('should allow just username and @ in URL', function () {
const result = pattern.split('http://aaa@bbb.ccc/ddd@eee');
expect(result.host).toEqual('bbb.ccc');
expect(result.path).toEqual('ddd@eee');
});

it('should allow @ in params', function () {
const result = pattern.split('http://aaa.bbb?ccc=@ddd');
expect(result.host).toEqual('aaa.bbb');
expect(result.params).toEqual('ccc=@ddd');
});

it('should allow @ in fragment', function () {
const result = pattern.split('http://aaa.bbb#@ccc');
expect(result.host).toEqual('aaa.bbb');
expect(result.fragment).toEqual('@ccc');
});

});

describe('getUrlParts', function() {
Expand Down
7 changes: 7 additions & 0 deletions test/real-life-examples.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,11 @@ describe('Real life examples', function() {
expect(my_match.test(url)).toBe(true);
});

it('should match fragment containing @', function () {
const pattern = '*://*/CustomerPortal/#/Page/HOME@folder-35';
const url = 'http://aaa.bbb/CustomerPortal/#/Page/HOME@folder-35';
const my_match = new UrlMatch(pattern);
expect(my_match.test(url)).toBe(true);
});

});

0 comments on commit cb3b3fa

Please sign in to comment.