Merge pull request #254 from matiu/bug/messagekey

catch bad message keys
This commit is contained in:
Gustavo Maximiliano Cortez 2014-11-18 15:52:22 -03:00
commit fe3a9142be

View File

@ -67,7 +67,14 @@ MessageDb.prototype.addMessage = function(m, cb) {
return; return;
} }
var key = messageKey(m.to); var key;
try {
key = messageKey(m.to);
} catch (e) {
cb(new Error('Bad message'));
return;
};
var value = m; var value = m;
this.db.put(key, value, cb); this.db.put(key, value, cb);
}; };
@ -102,13 +109,19 @@ MessageDb.fromStorage = function(data) {
}; };
MessageDb.prototype.getMessages = function(to, lower_ts, upper_ts, cb) { MessageDb.prototype.getMessages = function(to, lower_ts, upper_ts, cb) {
var list = []; var list = [],
opts;
lower_ts = lower_ts || 1; lower_ts = lower_ts || 1;
var opts = { try {
start: messageKey(to, lower_ts), opts = {
end: messageKey(to, upper_ts), start: messageKey(to, lower_ts),
// limit: limit, TODO end: messageKey(to, upper_ts),
reverse: false, // limit: limit, TODO
reverse: false,
};
} catch (e) {
cb(new Error('Bad message range'));
return;
}; };
db.createReadStream(opts) db.createReadStream(opts)