Skip to content

Commit aa551e4

Browse files
fix(params): Check for null in int param type is() check
Closes #3197
1 parent e0140c7 commit aa551e4

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/common/predicates.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
*
66
* @module common_predicates
77
*/ /** */
8-
import {and, not, pipe, prop} from "./hof";
8+
import { and, not, pipe, prop, compose, or } from "./hof";
99
import {Predicate} from "./common"; // has or is using
1010

1111
const toStr = Object.prototype.toString;
1212
const tis = (t: string) => (x: any) => typeof(x) === t;
1313
export const isUndefined = tis('undefined');
1414
export const isDefined = not(isUndefined);
1515
export const isNull = (o: any) => o === null;
16+
export const isNullOrUndefined = or(isNull, isUndefined);
1617
export const isFunction: (x: any) => x is Function = <any> tis('function');
1718
export const isNumber: (x: any) => x is number = <any> tis('number');
1819
export const isString = <(x: any) => x is string> tis('string');

src/params/paramTypes.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/** @module params */ /** for typedoc */
2-
import {fromJson, toJson, identity, equals, inherit, map, extend} from "../common/common";
3-
import {isDefined} from "../common/predicates";
4-
import {is, val} from "../common/hof";
5-
import {services} from "../common/coreservices";
6-
import {ParamType} from "./type";
7-
import {ParamTypeDefinition} from "./interface";
2+
import { fromJson, toJson, identity, equals, inherit, map, extend } from "../common/common";
3+
import { isDefined, isNullOrUndefined } from "../common/predicates";
4+
import { is } from "../common/hof";
5+
import { services } from "../common/coreservices";
6+
import { ParamType } from "./type";
7+
import { ParamTypeDefinition } from "./interface";
88

99
// Use tildes to pre-encode slashes.
1010
// If the slashes are simply URLEncoded, the browser can choose to pre-decode them,
@@ -35,7 +35,7 @@ export class ParamTypes {
3535
"int": {
3636
encode: valToString,
3737
decode(val: string) { return parseInt(val, 10); },
38-
is(val: any) { return isDefined(val) && this.decode(val.toString()) === val; },
38+
is(val: any) { return !isNullOrUndefined(val) && this.decode(val.toString()) === val; },
3939
pattern: /-?\d+/
4040
},
4141
"bool": {

0 commit comments

Comments
 (0)