mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
fix($route): fix regex escaping in route matcher
This commit is contained in:
parent
62ae7fccbc
commit
2bc39bb0b4
2 changed files with 25 additions and 2 deletions
|
|
@ -235,14 +235,16 @@ angularServiceInject('$route', function($location, $routeParams) {
|
|||
/////////////////////////////////////////////////////
|
||||
|
||||
function switchRouteMatcher(on, when) {
|
||||
var regex = '^' + when.replace(/[\.\\\(\)\^\$]/g, "\$1") + '$',
|
||||
// TODO(i): this code is convoluted and inefficient, we should construct the route matching
|
||||
// regex only once and then reuse it
|
||||
var regex = '^' + when.replace(/([\.\\\(\)\^\$])/g, "\\$1") + '$',
|
||||
params = [],
|
||||
dst = {};
|
||||
forEach(when.split(/\W/), function(param) {
|
||||
if (param) {
|
||||
var paramRegExp = new RegExp(":" + param + "([\\W])");
|
||||
if (regex.match(paramRegExp)) {
|
||||
regex = regex.replace(paramRegExp, "([^\/]*)$1");
|
||||
regex = regex.replace(paramRegExp, "([^\\/]*)$1");
|
||||
params.push(param);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,27 @@ describe('$route', function() {
|
|||
});
|
||||
|
||||
|
||||
it('should match a route that contains special chars in the path', function() {
|
||||
$route.when('/$test.23/foo(bar)/:baz', {template: 'test.html'});
|
||||
|
||||
$location.path('/test');
|
||||
scope.$digest();
|
||||
expect($route.current).toBeUndefined();
|
||||
|
||||
$location.path('/$testX23/foo(bar)/222');
|
||||
scope.$digest();
|
||||
expect($route.current).toBeUndefined();
|
||||
|
||||
$location.path('/$test.23/foo(bar)/222');
|
||||
scope.$digest();
|
||||
expect($route.current).toBeDefined();
|
||||
|
||||
$location.path('/$test.23/foo\\(bar)/222');
|
||||
scope.$digest();
|
||||
expect($route.current).toBeUndefined();
|
||||
});
|
||||
|
||||
|
||||
it('should change route even when only search param changes', function() {
|
||||
var callback = jasmine.createSpy('onRouteChange');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue