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

fix($location): prevent infinite digest with IDN urls in Edge #15235

Merged
merged 2 commits into from
Oct 17, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function parseAppUrl(relativeUrl, locationObj) {
}

function startsWith(haystack, needle) {
return haystack.lastIndexOf(needle, 0) === 0;
return haystack.indexOf(needle) === 0;
Copy link
Member

@gkalpak gkalpak Oct 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is worth adding a comment to prevent someone from "optimizing" it back in the future.

}

/**
Expand Down
10 changes: 9 additions & 1 deletion test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2450,10 +2450,11 @@ describe('$location', function() {


describe('LocationHtml5Url', function() {
var locationUrl, locationIndexUrl;
var locationUrl, locationUmlautUrl, locationIndexUrl;

beforeEach(function() {
locationUrl = new LocationHtml5Url('http://server/pre/', 'http://server/pre/', 'http://server/pre/path');
locationUmlautUrl = new LocationHtml5Url('http://särver/pre/', 'http://särver/pre/', 'http://särver/pre/path');
locationIndexUrl = new LocationHtml5Url('http://server/pre/index.html', 'http://server/pre/', 'http://server/pre/path');
});

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

expect(parseLinkAndReturn(locationUmlautUrl, 'http://other')).toEqual(undefined);
expect(parseLinkAndReturn(locationUmlautUrl, 'http://särver/pre')).toEqual('http://särver/pre/');
expect(parseLinkAndReturn(locationUmlautUrl, 'http://särver/pre/')).toEqual('http://särver/pre/');
expect(parseLinkAndReturn(locationUmlautUrl, 'http://särver/pre/otherPath')).toEqual('http://särver/pre/otherPath');
// Note: relies on the previous state!
expect(parseLinkAndReturn(locationUmlautUrl, 'someIgnoredAbsoluteHref', '#test')).toEqual('http://särver/pre/otherPath#test');

expect(parseLinkAndReturn(locationIndexUrl, 'http://server/pre')).toEqual('http://server/pre/');
expect(parseLinkAndReturn(locationIndexUrl, 'http://server/pre/')).toEqual('http://server/pre/');
expect(parseLinkAndReturn(locationIndexUrl, 'http://server/pre/otherPath')).toEqual('http://server/pre/otherPath');
Expand Down