@@ -15,7 +15,7 @@ export interface QueryParamAddFunction {
1515}
1616
1717export interface Route {
18- tokens : ( [ string , string ] | [ string , string , string ] | [ string , string , string , string ] | [ string , string , string , string , boolean ] ) [ ] ;
18+ tokens : ( string | boolean ) [ ] [ ] ;
1919 defaults : undefined [ ] | RouteDefaults ;
2020 requirements : undefined [ ] | RouteRequirements ;
2121 hosttokens : string [ ] [ ] ;
@@ -33,7 +33,7 @@ export interface Context {
3333 host : string ;
3434 port : string | null ;
3535 scheme : string ;
36- locale : string ;
36+ locale : string | null ;
3737}
3838
3939export interface RoutingData {
@@ -43,7 +43,7 @@ export interface RoutingData {
4343 host : string ;
4444 port ?: string | null ;
4545 scheme ?: string ;
46- locale ?: string ;
46+ locale ?: string | null ;
4747}
4848
4949export class Router {
@@ -130,11 +130,11 @@ export class Router {
130130 return this . context_ . port ;
131131 } ;
132132
133- setLocale ( locale : string ) {
133+ setLocale ( locale : string | null ) {
134134 this . context_ . locale = locale ;
135135 }
136136
137- getLocale ( ) : string {
137+ getLocale ( ) : string | null {
138138 return this . context_ . locale ;
139139 } ;
140140
@@ -194,22 +194,22 @@ export class Router {
194194 let port = ( typeof this . getPort ( ) == 'undefined' || this . getPort ( ) === null ) ? '' : this . getPort ( ) ;
195195
196196 route . tokens . forEach ( ( token ) => {
197- if ( 'text' === token [ 0 ] ) {
197+ if ( 'text' === token [ 0 ] && typeof token [ 1 ] === 'string' ) {
198198 url = Router . encodePathComponent ( token [ 1 ] ) + url ;
199199 optional = false ;
200200
201201 return ;
202202 }
203203
204204 if ( 'variable' === token [ 0 ] ) {
205- let hasDefault = route . defaults && ! Array . isArray ( route . defaults ) && token [ 3 ] && ( token [ 3 ] in route . defaults ) ;
206- if ( false === optional || ! hasDefault || ( ( token [ 3 ] && token [ 3 ] in params ) && ! Array . isArray ( route . defaults ) && params [ token [ 3 ] ] != route . defaults [ token [ 3 ] ] ) ) {
205+ let hasDefault = route . defaults && ! Array . isArray ( route . defaults ) && typeof token [ 3 ] === 'string' && ( token [ 3 ] in route . defaults ) ;
206+ if ( false === optional || ! hasDefault || ( ( typeof token [ 3 ] === 'string' && token [ 3 ] in params ) && ! Array . isArray ( route . defaults ) && params [ token [ 3 ] ] != route . defaults [ token [ 3 ] ] ) ) {
207207 let value ;
208208
209- if ( token [ 3 ] && token [ 3 ] in params ) {
209+ if ( typeof token [ 3 ] === 'string' && token [ 3 ] in params ) {
210210 value = params [ token [ 3 ] ] ;
211211 delete unusedParams [ token [ 3 ] ] ;
212- } else if ( token [ 3 ] && hasDefault && ! Array . isArray ( route . defaults ) ) {
212+ } else if ( typeof token [ 3 ] === 'string' && hasDefault && ! Array . isArray ( route . defaults ) ) {
213213 value = route . defaults [ token [ 3 ] ] ;
214214 } else if ( optional ) {
215215 return ;
@@ -230,7 +230,7 @@ export class Router {
230230 }
231231
232232 optional = false ;
233- } else if ( hasDefault && ( token [ 3 ] && token [ 3 ] in unusedParams ) ) {
233+ } else if ( hasDefault && ( typeof token [ 3 ] === 'string' && token [ 3 ] in unusedParams ) ) {
234234 delete unusedParams [ token [ 3 ] ] ;
235235 }
236236
0 commit comments