-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
The simple solution to drop special-cased `'back'` in `response.redirect`. I can't label but should be labeled as version-major. This PR **does not** make use of Symbol as purposed in #904. **Edit** If this solution is acceptable, a deprecation should be added to Koa 2 on `'back'` use. --------- Co-authored-by: Kevin Peno <kjpeno@outlook.com>
- Loading branch information
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict' | ||
|
||
const assert = require('assert') | ||
const context = require('../../test-helpers/context') | ||
|
||
describe('ctx.back([alt])', () => { | ||
it('should redirect to Referrer', () => { | ||
const ctx = context() | ||
ctx.req.headers.referrer = '/login' | ||
ctx.back() | ||
assert.equal(ctx.response.header.location, '/login') | ||
}) | ||
|
||
it('should redirect to Referer', () => { | ||
const ctx = context() | ||
ctx.req.headers.referer = '/login' | ||
ctx.back() | ||
assert.equal(ctx.response.header.location, '/login') | ||
}) | ||
|
||
it('should default to alt', () => { | ||
const ctx = context() | ||
ctx.back('/index.html') | ||
assert.equal(ctx.response.header.location, '/index.html') | ||
}) | ||
|
||
it('should default redirect to /', () => { | ||
const ctx = context() | ||
ctx.back() | ||
assert.equal(ctx.response.header.location, '/') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters