mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 17:16:14 +01:00
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:
committed by
GitHub
parent
0fffcb3855
commit
5917dec288
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user