Skip to content

Commit b1fb874

Browse files
committed
fix(ParamTypes): {int} should accept negatives
1 parent 2885551 commit b1fb874

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/params/paramTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ParamTypes {
3030
encode: valToString,
3131
decode(val) { return parseInt(val, 10); },
3232
is(val) { return isDefined(val) && this.decode(val.toString()) === val; },
33-
pattern: /\d+/
33+
pattern: /-?\d+/
3434
},
3535
bool: {
3636
encode: val => val && 1 || 0,

test/urlMatcherFactorySpec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@ describe("urlMatcherFactory", function () {
544544
var m = new UrlMatcher("/{foo:int}/{flag:bool}");
545545
expect(m.exec("/1138/1")).toEqual({ foo: 1138, flag: true });
546546
expect(m.format({ foo: 5, flag: true })).toBe("/5/1");
547+
548+
expect(m.exec("/-1138/1")).toEqual({ foo: -1138, flag: true });
549+
expect(m.format({ foo: -5, flag: true })).toBe("/-5/1");
547550
});
548551

549552
it("should match built-in types with spaces", function () {

0 commit comments

Comments
 (0)