@@ -59,6 +59,63 @@ describe('$route', function() {
5959    } ) ; 
6060  } ) ; 
6161
62+   it ( 'should route and fire change event when catch-all params are used' ,  function ( )  { 
63+     var  log  =  '' , 
64+         lastRoute , 
65+         nextRoute ; 
66+ 
67+     module ( function ( $routeProvider )  { 
68+       $routeProvider . when ( '/Book1/:book/Chapter/:chapter/*highlight' , 
69+           { controller : noop ,  templateUrl : 'Chapter.html' } ) ; 
70+       $routeProvider . when ( '/Book2/:book/*highlight/Chapter/:chapter' , 
71+           { controller : noop ,  templateUrl : 'Chapter.html' } ) ; 
72+       $routeProvider . when ( '/Blank' ,  { } ) ; 
73+     } ) ; 
74+     inject ( function ( $route ,  $location ,  $rootScope )  { 
75+       $rootScope . $on ( '$routeChangeStart' ,  function ( event ,  next ,  current )  { 
76+         log  +=  'before();' ; 
77+         expect ( current ) . toBe ( $route . current ) ; 
78+         lastRoute  =  current ; 
79+         nextRoute  =  next ; 
80+       } ) ; 
81+       $rootScope . $on ( '$routeChangeSuccess' ,  function ( event ,  current ,  last )  { 
82+         log  +=  'after();' ; 
83+         expect ( current ) . toBe ( $route . current ) ; 
84+         expect ( lastRoute ) . toBe ( last ) ; 
85+         expect ( nextRoute ) . toBe ( current ) ; 
86+       } ) ; 
87+ 
88+       $location . path ( '/Book1/Moby/Chapter/Intro/one' ) . search ( 'p=123' ) ; 
89+       $rootScope . $digest ( ) ; 
90+       $httpBackend . flush ( ) ; 
91+       expect ( log ) . toEqual ( 'before();after();' ) ; 
92+       expect ( $route . current . params ) . toEqual ( { book :'Moby' ,  chapter :'Intro' ,  highlight :'one' ,  p :'123' } ) ; 
93+ 
94+       log  =  '' ; 
95+       $location . path ( '/Blank' ) . search ( 'ignore' ) ; 
96+       $rootScope . $digest ( ) ; 
97+       expect ( log ) . toEqual ( 'before();after();' ) ; 
98+       expect ( $route . current . params ) . toEqual ( { ignore :true } ) ; 
99+ 
100+       log  =  '' ; 
101+       $location . path ( '/Book1/Moby/Chapter/Intro/one/two' ) . search ( 'p=123' ) ; 
102+       $rootScope . $digest ( ) ; 
103+       expect ( log ) . toEqual ( 'before();after();' ) ; 
104+       expect ( $route . current . params ) . toEqual ( { book :'Moby' ,  chapter :'Intro' ,  highlight :'one/two' ,  p :'123' } ) ; 
105+ 
106+       log  =  '' ; 
107+       $location . path ( '/Book2/Moby/one/two/Chapter/Intro' ) . search ( 'p=123' ) ; 
108+       $rootScope . $digest ( ) ; 
109+       expect ( log ) . toEqual ( 'before();after();' ) ; 
110+       expect ( $route . current . params ) . toEqual ( { book :'Moby' ,  chapter :'Intro' ,  highlight :'one/two' ,  p :'123' } ) ; 
111+ 
112+       log  =  '' ; 
113+       $location . path ( '/NONE' ) ; 
114+       $rootScope . $digest ( ) ; 
115+       expect ( log ) . toEqual ( 'before();after();' ) ; 
116+       expect ( $route . current ) . toEqual ( null ) ; 
117+     } ) ; 
118+   } ) ; 
62119
63120  it ( 'should not change route when location is canceled' ,  function ( )  { 
64121    module ( function ( $routeProvider )  { 
@@ -84,7 +141,7 @@ describe('$route', function() {
84141
85142  describe ( 'should match a route that contains special chars in the path' ,  function ( )  { 
86143    beforeEach ( module ( function ( $routeProvider )  { 
87-       $routeProvider . when ( '/$test.23/foo* (bar)/:baz' ,  { templateUrl : 'test.html' } ) ; 
144+       $routeProvider . when ( '/$test.23/foo(bar)/:baz' ,  { templateUrl : 'test.html' } ) ; 
88145    } ) ) ; 
89146
90147    it ( 'matches the full path' ,  inject ( function ( $route ,  $location ,  $rootScope )  { 
@@ -94,25 +151,19 @@ describe('$route', function() {
94151    } ) ) ; 
95152
96153    it ( 'matches literal .' ,  inject ( function ( $route ,  $location ,  $rootScope )  { 
97-       $location . path ( '/$testX23/foo*(bar)/222' ) ; 
98-       $rootScope . $digest ( ) ; 
99-       expect ( $route . current ) . toBeUndefined ( ) ; 
100-     } ) ) ; 
101- 
102-     it ( 'matches literal *' ,  inject ( function ( $route ,  $location ,  $rootScope )  { 
103-       $location . path ( '/$test.23/foooo(bar)/222' ) ; 
154+       $location . path ( '/$testX23/foo(bar)/222' ) ; 
104155      $rootScope . $digest ( ) ; 
105156      expect ( $route . current ) . toBeUndefined ( ) ; 
106157    } ) ) ; 
107158
108159    it ( 'treats backslashes normally' ,  inject ( function ( $route ,  $location ,  $rootScope )  { 
109-       $location . path ( '/$test.23/foo* \\(bar)/222' ) ; 
160+       $location . path ( '/$test.23/foo\\(bar)/222' ) ; 
110161      $rootScope . $digest ( ) ; 
111162      expect ( $route . current ) . toBeUndefined ( ) ; 
112163    } ) ) ; 
113164
114165    it ( 'matches a URL with special chars' ,  inject ( function ( $route ,  $location ,  $rootScope )  { 
115-       $location . path ( '/$test.23/foo* (bar)/222' ) ; 
166+       $location . path ( '/$test.23/foo(bar)/222' ) ; 
116167      $rootScope . $digest ( ) ; 
117168      expect ( $route . current ) . toBeDefined ( ) ; 
118169    } ) ) ; 
0 commit comments