diff --git a/src/route/util.ts b/src/route/util.ts index 9eb12df..41687bd 100644 --- a/src/route/util.ts +++ b/src/route/util.ts @@ -2,8 +2,9 @@ import {Context} from 'koa'; -export function ParseQueryNumber(s: string|undefined): number| undefined{ +export function ParseQueryNumber(s: string[] | string|undefined): number| undefined{ if(s === undefined) return undefined; + else if(typeof s === "object") return undefined; else return Number.parseInt(s); } export function ParseQueryArray(s: string[]|string|undefined){ @@ -11,19 +12,20 @@ export function ParseQueryArray(s: string[]|string|undefined){ const r = s instanceof Array ? s : [s]; return r.map(x=>decodeURIComponent(x)); } -export function ParseQueryArgString(s: string|undefined){ +export function ParseQueryArgString(s: string[]|string|undefined){ + if(typeof s === "object") return undefined; return s === undefined ? s : decodeURIComponent(s); } -export function ParseQueryBoolean(s: string|undefined): [boolean,boolean|undefined]{ +export function ParseQueryBoolean(s: string[] |string|undefined): [boolean,boolean|undefined]{ let value:boolean|undefined; + if(s === "true") value = true; else if(s === "false") value = false; else if(s === undefined) value = undefined; - else - return [false,undefined] + else return [false,undefined] return [true,value] }