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

Commit a348e90

Browse files
committed
fix($location): compare against actual instead of current URL
1 parent 4bd7bed commit a348e90

File tree

2 files changed

+67
-5
lines changed

2 files changed

+67
-5
lines changed

src/ng/location.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function LocationHtml5Url(appBase, basePrefix) {
128128
} else {
129129
return appBase + prevAppUrl;
130130
}
131-
} else if ( (appUrl = beginsWith(appBaseNoFile, url)) ) {
131+
} else if ( (appUrl = beginsWith(appBaseNoFile, url)) !== undefined ) {
132132
return appBaseNoFile + appUrl;
133133
} else if (appBaseNoFile == url + '/') {
134134
return appBaseNoFile;
@@ -524,12 +524,12 @@ function $LocationProvider(){
524524
if (elm[0] === $rootElement[0] || !(elm = elm.parent())[0]) return;
525525
}
526526

527-
var absHref = elm.prop('href'),
528-
rewrittenUrl = $location.$$rewrite(absHref);
527+
var absHref = elm.prop('href');
528+
var rewrittenUrl = $location.$$rewrite(absHref);
529529

530530
if (absHref && !elm.attr('target') && rewrittenUrl) {
531531
event.preventDefault();
532-
if (rewrittenUrl != initialUrl) {
532+
if (rewrittenUrl != $browser.url()) {
533533
// update location manually
534534
$location.$$parse(rewrittenUrl);
535535
$rootScope.$apply();

test/ng/locationSpec.js

+63-1
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,15 @@ describe('$location', function() {
826826
initLocation(),
827827
function($browser) {
828828
browserTrigger(link, 'click');
829-
expectNoRewrite($browser, 'http://host.com/base/');
829+
expectRewriteTo($browser, 'http://host.com/base/');
830+
831+
jqLite(link).attr('href', 'http://host.com/base/foo');
832+
browserTrigger(link, 'click');
833+
expectRewriteTo($browser, 'http://host.com/base/foo');
834+
835+
jqLite(link).attr('href', 'http://host.com/base/');
836+
browserTrigger(link, 'click');
837+
expectRewriteTo($browser, 'http://host.com/base/');
830838
}
831839
);
832840
});
@@ -1332,4 +1340,58 @@ describe('$location', function() {
13321340
});
13331341
});
13341342
});
1343+
1344+
describe('LocationHtml5Url', function() {
1345+
var location, locationIndex;
1346+
1347+
beforeEach(function() {
1348+
location = new LocationHtml5Url('http://server/pre/', 'http://server/pre/path');
1349+
locationIndex = new LocationHtml5Url('http://server/pre/index.html', 'http://server/pre/path');
1350+
});
1351+
1352+
it('should rewrite URL', function() {
1353+
expect(location.$$rewrite('http://other')).toEqual(undefined);
1354+
expect(location.$$rewrite('http://server/pre')).toEqual('http://server/pre/');
1355+
expect(location.$$rewrite('http://server/pre/')).toEqual('http://server/pre/');
1356+
expect(location.$$rewrite('http://server/pre/otherPath')).toEqual('http://server/pre/otherPath');
1357+
expect(locationIndex.$$rewrite('http://server/pre')).toEqual('http://server/pre/');
1358+
expect(locationIndex.$$rewrite('http://server/pre/')).toEqual('http://server/pre/');
1359+
expect(locationIndex.$$rewrite('http://server/pre/otherPath')).toEqual('http://server/pre/otherPath');
1360+
});
1361+
});
1362+
1363+
1364+
describe('LocationHashbangUrl', function() {
1365+
var location;
1366+
1367+
beforeEach(function() {
1368+
location = new LocationHashbangUrl('http://server/pre/', 'http://server/pre/#/path');
1369+
});
1370+
1371+
it('should rewrite URL', function() {
1372+
expect(location.$$rewrite('http://other')).toEqual(undefined);
1373+
expect(location.$$rewrite('http://server/pre/')).toEqual('http://server/pre/');
1374+
expect(location.$$rewrite('http://server/pre/#otherPath')).toEqual('http://server/pre/#otherPath');
1375+
});
1376+
});
1377+
1378+
1379+
describe('LocationHashbangInHtml5Url', function() {
1380+
var location, locationIndex;
1381+
1382+
beforeEach(function() {
1383+
location = new LocationHashbangInHtml5Url('http://server/pre/', '#!');
1384+
locationIndex = new LocationHashbangInHtml5Url('http://server/pre/index.html', '#!');
1385+
});
1386+
1387+
it('should rewrite URL', function() {
1388+
expect(location.$$rewrite('http://other')).toEqual(undefined);
1389+
expect(location.$$rewrite('http://server/pre')).toEqual('http://server/pre/');
1390+
expect(location.$$rewrite('http://server/pre/')).toEqual('http://server/pre/');
1391+
expect(location.$$rewrite('http://server/pre/otherPath')).toEqual('http://server/pre/#!otherPath');
1392+
expect(locationIndex.$$rewrite('http://server/pre')).toEqual('http://server/pre/');
1393+
expect(locationIndex.$$rewrite('http://server/pre/')).toEqual(undefined);
1394+
expect(locationIndex.$$rewrite('http://server/pre/otherPath')).toEqual('http://server/pre/index.html#!otherPath');
1395+
});
1396+
});
13351397
});

0 commit comments

Comments
 (0)