Skip to content

Commit

Permalink
fix(params): Check for null in int param type is() check
Browse files Browse the repository at this point in the history
Closes #3197
  • Loading branch information
christopherthielen committed Dec 16, 2016
1 parent e0140c7 commit aa551e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/common/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
*
* @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;
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 = <any> tis('function');
export const isNumber: (x: any) => x is number = <any> tis('number');
export const isString = <(x: any) => x is string> tis('string');
Expand Down
14 changes: 7 additions & 7 deletions src/params/paramTypes.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit aa551e4

Please sign in to comment.