Skip to content

Commit

Permalink
add test: when session contains multibyte character should still work
Browse files Browse the repository at this point in the history
  • Loading branch information
sodawy committed Jan 6, 2018
1 parent 5ff11fb commit a60955a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/session.js
Expand Up @@ -55,7 +55,7 @@ class Session {
}

/**
* Return how many values there are in the session object.
* Return how many keys there are in the session object.
* Used to see if it's "populated".
*
* @return {Number}
Expand Down
31 changes: 30 additions & 1 deletion test/cookie.test.js
Expand Up @@ -348,7 +348,7 @@ describe('Koa Session Cookie', () => {
});

describe('.length', () => {
it('should return session length', done => {
it('should return session`s keys length', done => {
const app = App();

app.use(async function(ctx) {
Expand Down Expand Up @@ -464,6 +464,35 @@ describe('Koa Session Cookie', () => {
.expect(500, done);
});
});

describe('contains multibyte character', () => {
it('should still work', done => {
const app = App();
const MULTIBYTE_CHAR = '€';

app.use(async function(ctx) {
if (ctx.method === 'POST') {
ctx.session.string = MULTIBYTE_CHAR;
ctx.status = 204;
} else {
ctx.body = ctx.session.string;
}
});

const server = app.listen();

request(server)
.post('/')
.expect(204, (err, res) => {
if (err) return done(err);
const cookie = res.headers['set-cookie'];
request(server)
.get('/')
.set('Cookie', cookie.join(';'))
.expect(MULTIBYTE_CHAR, done);
});
});
});
});

describe('when an error is thrown downstream and caught upstream', () => {
Expand Down

0 comments on commit a60955a

Please sign in to comment.