Skip to content

Commit 88052bf

Browse files
feat(redirect): Error after 20+ redirected transitions
1 parent 8ecb6c6 commit 88052bf

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/transition/transition.ts

+5
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,11 @@ export class Transition implements IHookRegistry {
551551
error() {
552552
let state: State = this.$to();
553553

554+
let redirects = 0, trans: Transition = this;
555+
while((trans = trans.redirectedFrom()) != null) {
556+
if (++redirects > 20) return `Too many Transition redirects (20+)`;
557+
}
558+
554559
if (state.self.abstract)
555560
return `Cannot transition to abstract state '${state.name}'`;
556561
if (!Param.validates(state.parameters(), this.params()))

test/core/stateServiceSpec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ describe('stateService', function () {
6262
.then(done, done);
6363
}));
6464

65+
it('should error after 20+ redirects', (done) => {
66+
let errors = [];
67+
$transitions.onEnter({ entering: "D" }, trans => trans.router.stateService.target('D'));
68+
$transitions.onError({}, trans => { errors.push(trans.error()) });
69+
70+
$state.defaultErrorHandler(function() {});
71+
72+
$state.go("D").catch(err => {
73+
expect(errors.length).toBe(21);
74+
expect(err.message).toContain('Too many Transition redirects');
75+
done();
76+
});
77+
})
78+
79+
6580
it("should not update the URL in response to synchronizing URL", ((done) => {
6681
$loc.setUrl('/a/b/c');
6782
spyOn($loc, 'setUrl').and.callThrough();

0 commit comments

Comments
 (0)