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

Commit

Permalink
fix($location): correctly parse link urls in hashbang mode with prefix
Browse files Browse the repository at this point in the history
This is a second fix for a regression that was introduced by 92a2e18.
The fix addresses scenarios when the $location service is configured with
a hash prefix.

Closes #1037
  • Loading branch information
mhevery authored and IgorMinar committed Jun 13, 2012
1 parent f6b09b9 commit 0f44964
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ function $LocationProvider(){

// update location with href without the prefix
href = absHref.substr(absUrlPrefix.length);
if (href.charAt(0) == '#') href = href.substr(1);
if (href.indexOf('#' + hashPrefix) == 0) href = href.substr(hashPrefix.length + 1);
$location.url(href);
$rootScope.$apply();
event.preventDefault();
Expand Down
30 changes: 30 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,36 @@ describe('$location', function() {
$rootElement.remove();
});
});


it('should not mess up hash urls when clicking on links in hashbang mode with a prefix',
function() {
var base;
module(function($locationProvider) {
return function($browser) {
window.location.hash = '!someHash';
$browser.url(base = window.location.href);
base = base.split('#')[0];
$locationProvider.hashPrefix('!');
}
});
inject(function($rootScope, $compile, $browser, $rootElement, $document, $location) {
// we need to do this otherwise we can't simulate events
$document.find('body').append($rootElement);

var element = $compile('<a href="#!/view1">v1</a><a href="#!/view2">v2</a>')($rootScope);
$rootElement.append(element);
var av1 = $rootElement.find('a').eq(0);
var av2 = $rootElement.find('a').eq(1);


browserTrigger(av1, 'click');
expect($browser.url()).toEqual(base + '#!/view1');

browserTrigger(av2, 'click');
expect($browser.url()).toEqual(base + '#!/view2');
});
});
});


Expand Down

0 comments on commit 0f44964

Please sign in to comment.