Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c1533ef

Browse files
committed
fix($location): support urls with any protocol
The url used for location parsing was quite strict and did not support custom url schemes like "chrome-extension://". With this change the only requirement for scheme is that it doesn't contain ":" character.
1 parent 679cb8a commit c1533ef

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/ng/location.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.-]*)(:([0-9]+))?(\/[^\?#]*)?(\?([^#]*))?(#(.*))?$/,
3+
var URL_MATCH = /^([^:]+):\/\/(\w+:{0,1}\w*@)?([\w\.-]*)(:([0-9]+))?(\/[^\?#]*)?(\?([^#]*))?(#(.*))?$/,
44
PATH_MATCH = /^([^\?#]*)?(\?([^#]*))?(#(.*))?$/,
55
HASH_MATCH = PATH_MATCH,
66
DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp': 21};

test/ng/locationSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,17 @@ describe('$location', function() {
632632

633633
expect(match[10]).toBe('?book=moby');
634634
});
635+
636+
637+
it('should parse chrome extension urls', function() {
638+
var match = URL_MATCH.exec('chrome-extension://jjcldkdmokihdaomalanmlohibnoplog/index.html?foo#bar');
639+
640+
expect(match[1]).toBe('chrome-extension');
641+
expect(match[3]).toBe('jjcldkdmokihdaomalanmlohibnoplog');
642+
expect(match[6]).toBe('/index.html');
643+
expect(match[8]).toBe('foo');
644+
expect(match[10]).toBe('bar');
645+
});
635646
});
636647

637648

0 commit comments

Comments
 (0)