Skip to content

Commit

Permalink
make scheme regex stricter
Browse files Browse the repository at this point in the history
It now must match `[a-zA-Z0-9+\-.]` as described in the RFC.

This means relative urls that happen to contain ‘:’ are more likely to
be recognised as relative providing they contain a character that does
not satisfy the above
  • Loading branch information
Tom Jenkinson committed Dec 28, 2017
1 parent 4ecbe26 commit a0d750d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/url-toolkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(function(root) {
/* jshint ignore:end */

var URL_REGEX = /^((?:[^\/;?#]+:)?)(\/\/[^\/\;?#]*)?(.*?)??(;.*?)?(\?.*?)?(#.*?)?$/;
var URL_REGEX = /^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/\;?#]*)?(.*?)??(;.*?)?(\?.*?)?(#.*?)?$/;
var FIRST_SEGMENT_REGEX = /^([^\/;?#]*)(.*)$/;
var SLASH_DOT_REGEX = /(?:\/|^)\.(?=\/)/g;
var SLASH_DOT_DOT_REGEX = /(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g;
Expand Down
4 changes: 4 additions & 0 deletions test/url-toolkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ describe('url toolkit', function() {
test('http://a/b/c/d;p?q', '..', 'http://a/b/');

test('http://a.com/b/cd/e.m3u8?test=1#something', '', 'http://a.com/b/cd/e.m3u8?test=1#something');

test('http://a.com/b/cd/e.m3u8?test=1#something', 'a_:b', 'http://a.com/b/cd/a_:b');
test('http://a.com/b/cd/e.m3u8?test=1#something', 'a:b', 'a:b');
test('http://a.com/b/cd/e.m3u8?test=1#something', './a:b', 'http://a.com/b/cd/a:b');
});
});

Expand Down

0 comments on commit a0d750d

Please sign in to comment.