fix: only allow numbers as scores (#7356)

* zadd score checks

* fix: only allow numbers as scores

* fix: convert values to strings
This commit is contained in:
Barış Soner Uşaklı
2019-02-11 11:23:18 -05:00
committed by GitHub
parent 0fffcb3855
commit 5917dec288
6 changed files with 76 additions and 20 deletions

View File

@@ -57,6 +57,31 @@ describe('Sorted Set methods', function () {
});
});
});
it('should error if score is null', function (done) {
db.sortedSetAdd('errorScore', null, 'value1', function (err) {
assert.equal(err.message, '[[error:invalid-score, null]]');
done();
});
});
it('should error if any score is undefined', function (done) {
db.sortedSetAdd('errorScore', [1, undefined], ['value1', 'value2'], function (err) {
assert.equal(err.message, '[[error:invalid-score, undefined]]');
done();
});
});
it('should add null value as `null` string', function (done) {
db.sortedSetAdd('nullValueZSet', 1, null, function (err) {
assert.ifError(err);
db.getSortedSetRange('nullValueZSet', 0, -1, function (err, values) {
assert.ifError(err);
assert.strictEqual(values[0], 'null');
done();
});
});
});
});
describe('sortedSetsAdd()', function () {
@@ -67,6 +92,14 @@ describe('Sorted Set methods', function () {
done();
});
});
it('should error if score is null', function (done) {
db.sortedSetsAdd(['sorted1', 'sorted2'], null, 'value1', function (err) {
assert.equal(err.message, '[[error:invalid-score, null]]');
done();
});
});
});
describe('getSortedSetRange()', function () {