Skip to content

Commit 0acb900

Browse files
committed
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 3e2cda5 commit 0acb900

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
@@ -2428,10 +2428,11 @@ describe('$location', function() {
24282428

24292429

24302430
describe('LocationHtml5Url', function() {
2431-
var locationUrl, locationIndexUrl;
2431+
var locationUrl, locationUmlautUrl, locationIndexUrl;
24322432

24332433
beforeEach(function() {
24342434
locationUrl = new LocationHtml5Url('http://server/pre/', 'http://server/pre/', 'http://server/pre/path');
2435+
locationUmlautUrl = new LocationHtml5Url('http://särver/pre/', 'http://särver/pre/', 'http://särver/pre/path');
24352436
locationIndexUrl = new LocationHtml5Url('http://server/pre/index.html', 'http://server/pre/', 'http://server/pre/path');
24362437
});
24372438

@@ -2443,6 +2444,13 @@ describe('$location', function() {
24432444
// Note: relies on the previous state!
24442445
expect(parseLinkAndReturn(locationUrl, 'someIgnoredAbsoluteHref', '#test')).toEqual('http://server/pre/otherPath#test');
24452446

2447+
expect(parseLinkAndReturn(locationUmlautUrl, 'http://other')).toEqual(undefined);
2448+
expect(parseLinkAndReturn(locationUmlautUrl, 'http://särver/pre')).toEqual('http://särver/pre/');
2449+
expect(parseLinkAndReturn(locationUmlautUrl, 'http://särver/pre/')).toEqual('http://särver/pre/');
2450+
expect(parseLinkAndReturn(locationUmlautUrl, 'http://särver/pre/otherPath')).toEqual('http://särver/pre/otherPath');
2451+
// Note: relies on the previous state!
2452+
expect(parseLinkAndReturn(locationUmlautUrl, 'someIgnoredAbsoluteHref', '#test')).toEqual('http://särver/pre/otherPath#test');
2453+
24462454
expect(parseLinkAndReturn(locationIndexUrl, 'http://server/pre')).toEqual('http://server/pre/');
24472455
expect(parseLinkAndReturn(locationIndexUrl, 'http://server/pre/')).toEqual('http://server/pre/');
24482456
expect(parseLinkAndReturn(locationIndexUrl, 'http://server/pre/otherPath')).toEqual('http://server/pre/otherPath');

0 commit comments

Comments
 (0)