Skip to content

Commit

Permalink
Fix for issue #49
Browse files Browse the repository at this point in the history
  • Loading branch information
chill117 committed Sep 15, 2016
1 parent a9ca691 commit 9e66a12
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var defaultOptions = {
expiration: 86400000,// The maximum age of a valid session; milliseconds.
createDatabaseTable: true,// Whether or not to create the sessions database table, if one does not already exist.
connectionLimit: 1,// Number of connections when creating a connection pool
charset: 'utf8mb4_bin',
schema: {
tableName: 'sessions',
columnNames: {
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ npm test

* TBD:
* Removed dependency on [mysql-connection-manager](https://github.com/chill117/mysql-connection-manager); now using connection pooling from [node-mysql](https://github.com/mysqljs/mysql) module.
* Fix for issue [#49](https://github.com/chill117/express-mysql-session/issues/46)
* v1.1.1:
* Fix for express-session integration when "cookie.maxAge" is set to NULL.
* v1.1.0:
Expand Down
6 changes: 3 additions & 3 deletions schema.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE TABLE IF NOT EXISTS `sessions` (
`session_id` varchar(255) COLLATE utf8_bin NOT NULL,
`session_id` varchar(128) COLLATE utf8mb4_bin NOT NULL,
`expires` int(11) unsigned NOT NULL,
`data` text,
`data` text COLLATE utf8mb4_bin,
PRIMARY KEY (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
) ENGINE=InnoDB
36 changes: 32 additions & 4 deletions test/unit/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ describe('set(session_id, data, cb)', function() {
async.each(fixtures, function(fixture, nextFixture) {

var session_id = fixture.session_id;
var data = {};

for (var key in fixture.data) {
data[key] = fixture.data[key];
}
// Clone the fixture data.
var data = JSON.parse(JSON.stringify(fixture.data));

data.new_attr = 'A new attribute!';
data.and_another = 'And another attribute..';
Expand All @@ -96,5 +94,35 @@ describe('set(session_id, data, cb)', function() {

}, done);
});

it('should be able to handle emojis and other utf8 characters in session data', function(done) {

var session_id = 'some-session-id';
var data = {};

data.text_with_emoji = 'Here is an emoji: 😆.';
data.and_more = 'And another one (😉)..'

sessionStore.set(session_id, data, function(error) {

try {
expect(error).to.equal(undefined);
} catch (error) {
return done(error);
}

sessionStore.get(session_id, function(error, session) {

try {
expect(error).to.equal(null);
expect(session).to.deep.equal(data);
} catch (error) {
return done(error);
}

done();
});
});
});
});
});

0 comments on commit 9e66a12

Please sign in to comment.