Skip to content

Commit 693ab69

Browse files
Narretzellimist
authored andcommitted
fix($location): prevent infinite digest with IDN urls in Edge
Internationalized Domain Urls, for example urls with Umlaut (Ä, Ö, Ü) cause infinite digest in Edge 38.14393.0.0 because lastIndexOf doesn't work correctly in this version when the search string is the same as the haystack string. The patch uses an implementation based on core.js: https://github.com/zloirock/core-js/blob/v2.4.1/modules/es6.string.starts-with.js#L16 Edge Bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9271625/ Fixes angular#15217 PR angular#15235
1 parent d3eb52e commit 693ab69

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/ng/location.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ function parseAppUrl(relativeUrl, locationObj) {
4848
}
4949
}
5050

51-
function startsWith(haystack, needle) {
52-
return haystack.lastIndexOf(needle, 0) === 0;
51+
function startsWith(str, search) {
52+
return str.slice(0, search.length) === search;
5353
}
5454

5555
/**

test/ng/locationSpec.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -2450,10 +2450,11 @@ describe('$location', function() {
24502450

24512451

24522452
describe('LocationHtml5Url', function() {
2453-
var locationUrl, locationIndexUrl;
2453+
var locationUrl, locationUmlautUrl, locationIndexUrl;
24542454

24552455
beforeEach(function() {
24562456
locationUrl = new LocationHtml5Url('http://server/pre/', 'http://server/pre/', 'http://server/pre/path');
2457+
locationUmlautUrl = new LocationHtml5Url('http://särver/pre/', 'http://särver/pre/', 'http://särver/pre/path');
24572458
locationIndexUrl = new LocationHtml5Url('http://server/pre/index.html', 'http://server/pre/', 'http://server/pre/path');
24582459
});
24592460

@@ -2465,6 +2466,13 @@ describe('$location', function() {
24652466
// Note: relies on the previous state!
24662467
expect(parseLinkAndReturn(locationUrl, 'someIgnoredAbsoluteHref', '#test')).toEqual('http://server/pre/otherPath#test');
24672468

2469+
expect(parseLinkAndReturn(locationUmlautUrl, 'http://other')).toEqual(undefined);
2470+
expect(parseLinkAndReturn(locationUmlautUrl, 'http://särver/pre')).toEqual('http://särver/pre/');
2471+
expect(parseLinkAndReturn(locationUmlautUrl, 'http://särver/pre/')).toEqual('http://särver/pre/');
2472+
expect(parseLinkAndReturn(locationUmlautUrl, 'http://särver/pre/otherPath')).toEqual('http://särver/pre/otherPath');
2473+
// Note: relies on the previous state!
2474+
expect(parseLinkAndReturn(locationUmlautUrl, 'someIgnoredAbsoluteHref', '#test')).toEqual('http://särver/pre/otherPath#test');
2475+
24682476
expect(parseLinkAndReturn(locationIndexUrl, 'http://server/pre')).toEqual('http://server/pre/');
24692477
expect(parseLinkAndReturn(locationIndexUrl, 'http://server/pre/')).toEqual('http://server/pre/');
24702478
expect(parseLinkAndReturn(locationIndexUrl, 'http://server/pre/otherPath')).toEqual('http://server/pre/otherPath');

0 commit comments

Comments
 (0)