From ff13227b2d8c5db889a34bf203f6a2ff8965b744 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Sat, 1 Nov 2014 20:12:05 +0100 Subject: [PATCH] feat($routeProvider): allow setting caseInsensitiveMatch on the provider Fixes #6477 --- src/ngRoute/route.js | 12 ++++++++++++ test/ngRoute/routeSpec.js | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index 7f5284ca5ff4..731a9bc17317 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -146,6 +146,9 @@ function $RouteProvider() { if (angular.isUndefined(routeCopy.reloadOnSearch)) { routeCopy.reloadOnSearch = true; } + if (angular.isUndefined(routeCopy.caseInsensitiveMatch)) { + routeCopy.caseInsensitiveMatch = this.caseInsensitiveMatch; + } routes[path] = angular.extend( routeCopy, path && pathRegExp(path, routeCopy) @@ -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 diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js index 009c6d2dd43a..fb265a2020d9 100644 --- a/test/ngRoute/routeSpec.js +++ b/test/ngRoute/routeSpec.js @@ -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'); + }); + }); it('should not change route when location is canceled', function() { module(function($routeProvider) {