File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,8 @@ export default class Param {
3838 }
3939
4040 function getType ( config , urlType , location ) {
41- if ( config . type && urlType ) throw new Error ( `Param '${ id } ' has two type configurations.` ) ;
41+ if ( config . type && urlType && urlType . name !== 'string' ) throw new Error ( `Param '${ id } ' has two type configurations.` ) ;
42+ if ( config . type && urlType && urlType . name === 'string' && paramTypes . type ( config . type ) ) return paramTypes . type ( config . type ) ;
4243 if ( urlType ) return urlType ;
4344 if ( ! config . type ) return ( location === "config" ? paramTypes . type ( "any" ) : paramTypes . type ( "string" ) ) ;
4445 return config . type instanceof Type ? config . type : paramTypes . type ( config . type ) ;
Original file line number Diff line number Diff line change @@ -550,6 +550,21 @@ describe("urlMatcherFactory", function () {
550550 expect ( m . format ( { foo : 5 , flag : true } ) ) . toBe ( "/5/1" ) ;
551551 } ) ;
552552
553+ it ( "should match types named only in params" , function ( ) {
554+ var m = new UrlMatcher ( "/{foo}/{flag}" , {
555+ params : {
556+ foo : {
557+ type : 'int'
558+ } ,
559+ flag : {
560+ type : 'bool'
561+ }
562+ }
563+ } ) ;
564+ expect ( m . exec ( "/1138/1" ) ) . toEqual ( { foo : 1138 , flag : true } ) ;
565+ expect ( m . format ( { foo : 5 , flag : true } ) ) . toBe ( "/5/1" ) ;
566+ } ) ;
567+
553568 it ( "should encode/decode dates" , function ( ) {
554569 var m = new UrlMatcher ( "/calendar/{date:date}" ) ,
555570 result = m . exec ( "/calendar/2014-03-26" ) ;
You can’t perform that action at this time.
0 commit comments