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

Commit ea818eb

Browse files
fix($location): throw if the path starts with double (back)slashes
Previously `$location` was rewriting such paths to remove not only the double slashes but also the first segment of the path, leading to an invalid path. In this change, we deem leading double (back)slashes an invalid path and now throw a `$location:badpath` error if that occurs.
1 parent 7d2a35a commit ea818eb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/ng/location.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ function parseAbsoluteUrl(absoluteUrl, locationObj) {
3030
locationObj.$$port = toInt(parsedUrl.port) || DEFAULT_PORTS[parsedUrl.protocol] || null;
3131
}
3232

33-
var DOUBLE_SLASH_REGEX = /\s*[\\/]{2,}/;
33+
var DOUBLE_SLASH_REGEX = /^\s*[\\/]{2,}/;
3434
function parseAppUrl(url, locationObj) {
3535

36-
if (url.search(DOUBLE_SLASH_REGEX) === 0) {
36+
if (DOUBLE_SLASH_REGEX.test(url)) {
3737
throw $locationMinErr('badpath', 'Invalid url "{0}".', url);
3838
}
3939

test/ng/locationSpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -2488,6 +2488,10 @@ describe('$location', function() {
24882488
expect(function() {
24892489
parseLinkAndReturn(locationUrl, 'http://server/pre/\\\\other/path');
24902490
}).toThrowMinErr('$location', 'badpath');
2491+
2492+
expect(function() {
2493+
parseLinkAndReturn(locationUrl, 'http://server/pre//\\//other/path');
2494+
}).toThrowMinErr('$location', 'badpath');
24912495
});
24922496

24932497
it('should complain if no base tag present', function() {

0 commit comments

Comments
 (0)