@@ -96,6 +96,9 @@ describe('state', function () {
96
96
. state ( 'badParam' , {
97
97
url : "/bad/{param:int}"
98
98
} )
99
+ . state ( 'badParam2' , {
100
+ url : "/bad2/{param:[0-9]{5}}"
101
+ } )
99
102
100
103
. state ( 'first' , { url : '^/first/subpath' } )
101
104
. state ( 'second' , { url : '^/second' } )
@@ -755,6 +758,7 @@ describe('state', function () {
755
758
'about.sidebar' ,
756
759
'about.sidebar.item' ,
757
760
'badParam' ,
761
+ 'badParam2' ,
758
762
'dynamicController' ,
759
763
'first' ,
760
764
'home' ,
@@ -875,6 +879,29 @@ describe('state', function () {
875
879
$rootScope . $apply ( ) ;
876
880
expect ( $state . current . name ) . toBe ( "about" ) ;
877
881
} ) ) ;
882
+
883
+ it ( 'should ignore bad state parameters' , inject ( function ( $state , $rootScope , $location , $stateParams ) {
884
+ $state . go ( "badParam" , { param : 5 } ) ;
885
+ $rootScope . $apply ( ) ;
886
+ expect ( $state . current . name ) . toBe ( "badParam" ) ;
887
+ expect ( $stateParams ) . toEqual ( { param : 5 } ) ;
888
+
889
+ $state . go ( "badParam2" , { param : '12345' } ) ; // must be 5 digits
890
+ $rootScope . $apply ( ) ;
891
+ expect ( $state . current . name ) . toBe ( "badParam2" ) ;
892
+
893
+ $state . go ( "about" ) ;
894
+ $rootScope . $apply ( ) ;
895
+ expect ( $state . current . name ) . toBe ( 'about' ) ;
896
+
897
+ $state . go ( "badParam" , { param : 'foo' } ) ;
898
+ $rootScope . $apply ( ) ;
899
+ expect ( $state . current . name ) . toBe ( "about" ) ;
900
+
901
+ $state . go ( "badParam2" , { param : '1234' } ) ; // must be 5 digits
902
+ $rootScope . $apply ( ) ;
903
+ expect ( $state . current . name ) . toBe ( "about" ) ;
904
+ } ) ) ;
878
905
} ) ;
879
906
880
907
it ( 'should revert to last known working url on state change failure' , inject ( function ( $state , $rootScope , $location , $q ) {
0 commit comments