Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Commit b3950ea

Browse files
KatonRyuchristopherthielen
authored andcommitted
fix(int): Negative parameter values (PR #3301)
* Backport for issue #2422 Negative parameters are now supported. * Test fix for #2422 * Negative param fix Closes #2422
1 parent 5fd8177 commit b3950ea

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

release/angular-ui-router.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ function $UrlMatcherFactory() {
13451345
encode: valToString,
13461346
decode: function(val) { return parseInt(val, 10); },
13471347
is: function(val) { return val !== undefined && val !== null && this.decode(val.toString()) === val; },
1348-
pattern: /\d+/
1348+
pattern: /-?\d+/
13491349
},
13501350
"bool": {
13511351
encode: function(val) { return val ? 1 : 0; },
@@ -4681,4 +4681,4 @@ function $IncludedByStateFilter($state) {
46814681
angular.module('ui.router.state')
46824682
.filter('isState', $IsStateFilter)
46834683
.filter('includedByState', $IncludedByStateFilter);
4684-
})(window, window.angular);
4684+
})(window, window.angular);

src/urlMatcherFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ function $UrlMatcherFactory() {
611611
encode: valToString,
612612
decode: function(val) { return parseInt(val, 10); },
613613
is: function(val) { return val !== undefined && val !== null && this.decode(val.toString()) === val; },
614-
pattern: /\d+/
614+
pattern: /-?\d+/
615615
},
616616
"bool": {
617617
encode: function(val) { return val ? 1 : 0; },

test/urlMatcherFactorySpec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,9 @@ describe("urlMatcherFactory", function () {
599599
var m = new UrlMatcher("/{foo:int}/{flag:bool}");
600600
expect(m.exec("/1138/1")).toEqual({ foo: 1138, flag: true });
601601
expect(m.format({ foo: 5, flag: true })).toBe("/5/1");
602+
603+
expect(m.exec("/-1138/1")).toEqual({ foo: -1138, flag: true });
604+
expect(m.format({ foo: -5, flag: true })).toBe("/-5/1");
602605
});
603606

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

0 commit comments

Comments
 (0)