Skip to content

Commit

Permalink
feat(redirect): Error after 20+ redirected transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Sep 9, 2016
1 parent 8ecb6c6 commit 88052bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/transition/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,11 @@ export class Transition implements IHookRegistry {
error() {
let state: State = this.$to();

let redirects = 0, trans: Transition = this;
while((trans = trans.redirectedFrom()) != null) {
if (++redirects > 20) return `Too many Transition redirects (20+)`;
}

if (state.self.abstract)
return `Cannot transition to abstract state '${state.name}'`;
if (!Param.validates(state.parameters(), this.params()))
Expand Down
15 changes: 15 additions & 0 deletions test/core/stateServiceSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ describe('stateService', function () {
.then(done, done);
}));

it('should error after 20+ redirects', (done) => {
let errors = [];
$transitions.onEnter({ entering: "D" }, trans => trans.router.stateService.target('D'));
$transitions.onError({}, trans => { errors.push(trans.error()) });

$state.defaultErrorHandler(function() {});

$state.go("D").catch(err => {
expect(errors.length).toBe(21);
expect(err.message).toContain('Too many Transition redirects');
done();
});
})


it("should not update the URL in response to synchronizing URL", ((done) => {
$loc.setUrl('/a/b/c');
spyOn($loc, 'setUrl').and.callThrough();
Expand Down

0 comments on commit 88052bf

Please sign in to comment.