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

feat($routeProvider): allow setting caseInsensitiveMatch on the provider #9873

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions src/ngRoute/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ function $RouteProvider() {
if (angular.isUndefined(routeCopy.reloadOnSearch)) {
routeCopy.reloadOnSearch = true;
}
if (angular.isUndefined(routeCopy.caseInsensitiveMatch)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should use if (!'prop' in routeCopy) instead, since that's really what we're testing. Either way, looks fine to me

routeCopy.caseInsensitiveMatch = this.caseInsensitiveMatch;
}
routes[path] = angular.extend(
routeCopy,
path && pathRegExp(path, routeCopy)
Expand All @@ -166,6 +169,15 @@ function $RouteProvider() {
return this;
};

/**
* @ngdoc property
* @name $routeProvider#caseInsensitiveMatch
*
* @property {boolean} caseInsensitiveMatch Value of the `caseInsensitiveMatch` property
* for newly defined routes. Defaults to `false`.
*/
this.caseInsensitiveMatch = false;

/**
* @param path {string} path
* @param opts {Object} options
Expand Down
25 changes: 25 additions & 0 deletions test/ngRoute/routeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,31 @@ describe('$route', function() {
});
});

it('should allow configuring caseInsensitiveMatch on the route provider level', function() {
module(function($routeProvider) {
$routeProvider.caseInsensitiveMatch = true;
$routeProvider.when('/Blank', {template: 'blank'});
$routeProvider.otherwise({template: 'other'});
});
inject(function($route, $location, $rootScope) {
$location.path('/bLaNk');
$rootScope.$digest();
expect($route.current.template).toBe('blank');
});
});

it('should allow overriding provider\'s caseInsensitiveMatch setting on the route level', function() {
module(function($routeProvider) {
$routeProvider.caseInsensitiveMatch = true;
$routeProvider.when('/Blank', {template: 'blank', caseInsensitiveMatch: false});
$routeProvider.otherwise({template: 'other'});
});
inject(function($route, $location, $rootScope) {
$location.path('/bLaNk');
$rootScope.$digest();
expect($route.current.template).toBe('other');
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

you could add 2 extra variations of these tests, but it's fine without them too


it('should not change route when location is canceled', function() {
module(function($routeProvider) {
Expand Down