Skip to content

Commit

Permalink
fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpeno committed Oct 20, 2024
1 parent bba5d05 commit a231946
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
12 changes: 6 additions & 6 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const only = require('./only.js')
const util = require('util')
const encodeUrl = require('encodeurl')
const Stream = require('stream')
const deprecate = require('depd')('koa');
const deprecate = require('depd')('koa')

/**
* Prototype.
Expand Down Expand Up @@ -296,8 +296,8 @@ module.exports = {
// location
if (url === 'back') {
deprecate('Special-cased string "back" through redirect will be removed in v3, ' +
'consider migrating usage to ctx.back() instead.');
url = this.ctx.get('Referrer') || alt || '/';
'consider migrating usage to ctx.back() instead.')
url = this.ctx.get('Referrer') || alt || '/'
}
if (/^https?:\/\//i.test(url)) {
// formatting url again avoid security escapes
Expand Down Expand Up @@ -334,9 +334,9 @@ module.exports = {
* @api public
*/

back(alt) {
const url = this.ctx.get('Referrer') || alt || '/';
this.redirect(url);
back (alt) {

Check warning on line 337 in lib/response.js

View check run for this annotation

Codecov / codecov/patch

lib/response.js#L337

Added line #L337 was not covered by tests
const url = this.ctx.get('Referrer') || alt || '/'
this.redirect(url)

Check warning on line 339 in lib/response.js

View check run for this annotation

Codecov / codecov/patch

lib/response.js#L339

Added line #L339 was not covered by tests
},

/**
Expand Down
45 changes: 22 additions & 23 deletions test/response/back.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
'use strict'

'use strict';

const assert = require('assert');
const context = require('../helpers/context');
const assert = require('assert')
const context = require('../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');
});
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');
});
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');
});
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, '/');
});
});
const ctx = context()
ctx.back()
assert.equal(ctx.response.header.location, '/')
})
})

0 comments on commit a231946

Please sign in to comment.