From aa551e4252e784a49fda93865f1d1c03b4e36017 Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Thu, 15 Dec 2016 18:02:04 -0600 Subject: [PATCH] fix(params): Check for null in `int` param type `is()` check Closes #3197 --- src/common/predicates.ts | 3 ++- src/params/paramTypes.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/common/predicates.ts b/src/common/predicates.ts index c0996609..ece248ab 100644 --- a/src/common/predicates.ts +++ b/src/common/predicates.ts @@ -5,7 +5,7 @@ * * @module common_predicates */ /** */ -import {and, not, pipe, prop} from "./hof"; +import { and, not, pipe, prop, compose, or } from "./hof"; import {Predicate} from "./common"; // has or is using const toStr = Object.prototype.toString; @@ -13,6 +13,7 @@ const tis = (t: string) => (x: any) => typeof(x) === t; export const isUndefined = tis('undefined'); export const isDefined = not(isUndefined); export const isNull = (o: any) => o === null; +export const isNullOrUndefined = or(isNull, isUndefined); export const isFunction: (x: any) => x is Function = tis('function'); export const isNumber: (x: any) => x is number = tis('number'); export const isString = <(x: any) => x is string> tis('string'); diff --git a/src/params/paramTypes.ts b/src/params/paramTypes.ts index d91d43df..d13537eb 100644 --- a/src/params/paramTypes.ts +++ b/src/params/paramTypes.ts @@ -1,10 +1,10 @@ /** @module params */ /** for typedoc */ -import {fromJson, toJson, identity, equals, inherit, map, extend} from "../common/common"; -import {isDefined} from "../common/predicates"; -import {is, val} from "../common/hof"; -import {services} from "../common/coreservices"; -import {ParamType} from "./type"; -import {ParamTypeDefinition} from "./interface"; +import { fromJson, toJson, identity, equals, inherit, map, extend } from "../common/common"; +import { isDefined, isNullOrUndefined } from "../common/predicates"; +import { is } from "../common/hof"; +import { services } from "../common/coreservices"; +import { ParamType } from "./type"; +import { ParamTypeDefinition } from "./interface"; // Use tildes to pre-encode slashes. // If the slashes are simply URLEncoded, the browser can choose to pre-decode them, @@ -35,7 +35,7 @@ export class ParamTypes { "int": { encode: valToString, decode(val: string) { return parseInt(val, 10); }, - is(val: any) { return isDefined(val) && this.decode(val.toString()) === val; }, + is(val: any) { return !isNullOrUndefined(val) && this.decode(val.toString()) === val; }, pattern: /-?\d+/ }, "bool": {