Skip to content
Permalink
Browse files

fix(ngRoute): allow proto inherited properties in route params object

copy route params with angular.copy before using angular.extend which looks only for enumerable own
properties

Closes #8181
Closes #9731
  • Loading branch information
cmichal authored and caitp committed Oct 21, 2014
1 parent 2a2fd14 commit b4770582f84f26c8ff7f2320a36a6b0ceff6e6cc
Showing with 23 additions and 4 deletions.
  1. +8 −4 src/ngRoute/route.js
  2. +15 −0 test/ngRoute/routeSpec.js
@@ -141,10 +141,14 @@ function $RouteProvider() {
* Adds a new route definition to the `$route` service.
*/
this.when = function(path, route) {
//copy original route object to preserve params inherited from proto chain
var routeCopy = angular.copy(route);
if (angular.isUndefined(routeCopy.reloadOnSearch)) {
routeCopy.reloadOnSearch = true;
}
routes[path] = angular.extend(
{reloadOnSearch: true},
route,
path && pathRegExp(path, route)
routeCopy,
path && pathRegExp(path, routeCopy)
);

// create redirection for trailing slashes
@@ -155,7 +159,7 @@ function $RouteProvider() {

routes[redirectPath] = angular.extend(
{redirectTo: path},
pathRegExp(redirectPath, route)
pathRegExp(redirectPath, routeCopy)
);
}

@@ -294,6 +294,21 @@ describe('$route', function() {
$rootScope.$digest();
expect($route.current).toBeDefined();
}));

it("should use route params inherited from prototype chain", function() {
function BaseRoute() {}
BaseRoute.prototype.templateUrl = 'foo.html';

module(function($routeProvider) {
$routeProvider.when('/foo', new BaseRoute);
});

inject(function($route, $location, $rootScope) {
$location.path('/foo');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('foo.html');
});
});
});


1 comment on commit b477058

@gackt

This comment has been minimized.

Copy link

@gackt gackt commented on b477058 Nov 18, 2014

This fix would cause a problem when 'route' is undefined. Test code which calls $routeProvider.otherwise() would be broken.

Please sign in to comment.
You can’t perform that action at this time.