From e8e33a8a23cdbc1d44d975a549fb3d2aa3277a53 Mon Sep 17 00:00:00 2001 From: Moritz Schmidt Date: Sun, 4 Dec 2016 17:41:27 +0100 Subject: [PATCH 01/11] ZSET scores are float: parseInt => parseFloat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Redis, scores of sorted sets can be floats – so we should use `parseFloat` instead of `parseInt` when converting from string to number. Should not lead to #4939 again, as `new Date()` works regardless of whether it's being passed a float or integer. --- src/database/redis/sorted.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/database/redis/sorted.js b/src/database/redis/sorted.js index 2230f0498a..9e50c158c7 100644 --- a/src/database/redis/sorted.js +++ b/src/database/redis/sorted.js @@ -115,7 +115,7 @@ module.exports = function (redisClient, module) { } var objects = []; for(var i = 0; i < data.length; i += 2) { - objects.push({value: data[i], score: parseInt(data[i + 1], 10)}); + objects.push({value: data[i], score: parseFloat(data[i + 1])}); } callback(null, objects); }); @@ -144,7 +144,7 @@ module.exports = function (redisClient, module) { } var objects = []; for(var i = 0; i < data.length; i += 2) { - objects.push({value: data[i], score: parseInt(data[i + 1], 10)}); + objects.push({value: data[i], score: parseFloat(data[i + 1])}); } callback(null, objects); }); @@ -195,7 +195,7 @@ module.exports = function (redisClient, module) { module.sortedSetScore = function (key, value, callback) { redisClient.zscore(key, value, function (err, score) { - callback(err, !err ? parseInt(score, 10) : undefined); + callback(err, !err ? parseFloat(score) : undefined); }); }; @@ -289,7 +289,7 @@ module.exports = function (redisClient, module) { results = results[1] || []; var objects = []; for(var i = 0; i < results.length; i += 2) { - objects.push({value: results[i], score: parseInt(results[i + 1], 10)}); + objects.push({value: results[i], score: parseFloat(results[i + 1])}); } callback(null, objects); }); @@ -297,7 +297,7 @@ module.exports = function (redisClient, module) { module.sortedSetIncrBy = function (key, increment, value, callback) { redisClient.zincrby(key, increment, value, function (err, newValue) { - callback(err, !err ? parseInt(newValue, 10) : undefined); + callback(err, !err ? parseFloat(newValue) : undefined); }); }; @@ -419,4 +419,4 @@ module.exports = function (redisClient, module) { callback(null, objects); }); } -}; \ No newline at end of file +}; From 7c697759e9da678cee23561ce413da0d75f7bc64 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Thu, 1 Dec 2016 17:06:53 -0700 Subject: [PATCH 02/11] Escape and ignore `%` and `\,` in translator args --- public/src/modules/translator.js | 5 +++-- test/translator.js | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index a876dba44c..e60385ed79 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -105,7 +105,7 @@ } else if (text.slice(i, i + 2) === ']]') { level -= 1; i += 1; - } else if (level === 0 && text[i] === ',') { + } else if (level === 0 && text[i] === ',' && text[i - 1] !== '\\') { arr.push(text.slice(brk, i).trim()); i += 1; brk = i; @@ -260,7 +260,8 @@ } var out = translated; translatedArgs.forEach(function (arg, i) { - out = out.replace(new RegExp('%' + (i + 1), 'g'), arg); + var escaped = arg.replace(/%/g, '%').replace(/\\,/g, ','); + out = out.replace(new RegExp('%' + (i + 1), 'g'), escaped); }); return out; }); diff --git a/test/translator.js b/test/translator.js index 91fbf8f696..f52fd7c79c 100644 --- a/test/translator.js +++ b/test/translator.js @@ -127,14 +127,13 @@ describe('new Translator(language)', function () { }); }); - it('should properly escape % and ,', function (done) { + it('should properly escape and ignore % and \\, in arguments', function (done) { var translator = Translator.create('en-GB'); - var title = 'Test 1, 2, 3 % salmon'; - title = title.replace(/%/g, '%').replace(/,/g, ','); + var title = 'Test 1\\, 2\\, 3 % salmon'; var key = "[[topic:composer.replying_to, " + title + "]]"; translator.translate(key).then(function (translated) { - assert.strictEqual(translated, 'Replying to Test 1, 2, 3 % salmon'); + assert.strictEqual(translated, 'Replying to Test 1, 2, 3 % salmon'); done(); }); }); From 375af7ad53a21514d289acffbe561665731bcce9 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Thu, 1 Dec 2016 17:09:09 -0700 Subject: [PATCH 03/11] Restructure and rename translator tests --- test/translator.js | 100 ++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 60 deletions(-) diff --git a/test/translator.js b/test/translator.js index f52fd7c79c..60fb589e0d 100644 --- a/test/translator.js +++ b/test/translator.js @@ -7,7 +7,7 @@ var Translator = shim.Translator; require('../src/languages').init(function () {}); -describe('translator shim', function () { +describe('Translator shim', function () { describe('.translate()', function () { it('should translate correctly', function (done) { shim.translate('[[global:pagination.out_of, (foobar), [[global:home]]]]', function (translated) { @@ -15,6 +15,13 @@ describe('translator shim', function () { done(); }); }); + + it('should accept a language parameter and adjust accordingly', function (done) { + shim.translate('[[global:home]]', 'de', function (translated) { + assert.strictEqual(translated, 'Übersicht'); + done(); + }); + }); }); }); @@ -27,138 +34,115 @@ describe('new Translator(language)', function () { }); describe('.translate()', function () { - it('should handle basic translations', function (done) { + it('should handle basic translations', function () { var translator = Translator.create('en-GB'); - translator.translate('[[global:home]]').then(function (translated) { + return translator.translate('[[global:home]]').then(function (translated) { assert.strictEqual(translated, 'Home'); - done(); }); }); - it('should handle language keys in regular text', function (done) { + it('should handle language keys in regular text', function () { var translator = Translator.create('en-GB'); - translator.translate('Let\'s go [[global:home]]').then(function (translated) { + return translator.translate('Let\'s go [[global:home]]').then(function (translated) { assert.strictEqual(translated, 'Let\'s go Home'); - done(); - }); - }); - - it('should accept a language parameter and adjust accordingly', function (done) { - var translator = Translator.create('de'); - - translator.translate('[[global:home]]').then(function (translated) { - assert.strictEqual(translated, 'Übersicht'); - done(); }); }); - it('should handle language keys in regular text with another language specified', function (done) { + it('should handle language keys in regular text with another language specified', function () { var translator = Translator.create('de'); - translator.translate('[[global:home]] test').then(function (translated) { + return translator.translate('[[global:home]] test').then(function (translated) { assert.strictEqual(translated, 'Übersicht test'); - done(); }); }); - it('should handle language keys with parameters', function (done) { + it('should handle language keys with parameters', function () { var translator = Translator.create('en-GB'); - translator.translate('[[global:pagination.out_of, 1, 5]]').then(function (translated) { + return translator.translate('[[global:pagination.out_of, 1, 5]]').then(function (translated) { assert.strictEqual(translated, '1 out of 5'); - done(); }); }); - it('should handle language keys inside language keys', function (done) { + it('should handle language keys inside language keys', function () { var translator = Translator.create('en-GB'); - translator.translate('[[notifications:outgoing_link_message, [[global:guest]]]]').then(function (translated) { + return translator.translate('[[notifications:outgoing_link_message, [[global:guest]]]]').then(function (translated) { assert.strictEqual(translated, 'You are now leaving Guest'); - done(); }); }); - it('should handle language keys inside language keys with multiple parameters', function (done) { + it('should handle language keys inside language keys with multiple parameters', function () { var translator = Translator.create('en-GB'); - translator.translate('[[notifications:user_posted_to, [[global:guest]], My Topic]]').then(function (translated) { + return translator.translate('[[notifications:user_posted_to, [[global:guest]], My Topic]]').then(function (translated) { assert.strictEqual(translated, 'Guest has posted a reply to: My Topic'); - done(); }); }); - it('should handle language keys inside language keys with all parameters as language keys', function (done) { + it('should handle language keys inside language keys with all parameters as language keys', function () { var translator = Translator.create('en-GB'); - translator.translate('[[notifications:user_posted_to, [[global:guest]], [[global:guest]]]]').then(function (translated) { + return translator.translate('[[notifications:user_posted_to, [[global:guest]], [[global:guest]]]]').then(function (translated) { assert.strictEqual(translated, 'Guest has posted a reply to: Guest'); - done(); }); }); - it('should properly handle parameters that contain square brackets', function (done) { + it('should properly handle parameters that contain square brackets', function () { var translator = Translator.create('en-GB'); - translator.translate('[[global:pagination.out_of, [guest], [[global:home]]]]').then(function (translated) { + return translator.translate('[[global:pagination.out_of, [guest], [[global:home]]]]').then(function (translated) { assert.strictEqual(translated, '[guest] out of Home'); - done(); }); }); - it('should properly handle parameters that contain parentheses', function (done) { + it('should properly handle parameters that contain parentheses', function () { var translator = Translator.create('en-GB'); - translator.translate('[[global:pagination.out_of, (foobar), [[global:home]]]]').then(function (translated) { + return translator.translate('[[global:pagination.out_of, (foobar), [[global:home]]]]').then(function (translated) { assert.strictEqual(translated, '(foobar) out of Home'); - done(); }); }); - it('should not translate language key parameters with HTML in them', function (done) { + it('should escape language key parameters with HTML in them', function () { var translator = Translator.create('en-GB'); var key = '[[global:403.login, test]]'; - translator.translate(key).then(function (translated) { + return translator.translate(key).then(function (translated) { assert.strictEqual(translated, 'Perhaps you should try logging in?'); - done(); }); }); - it('should properly escape and ignore % and \\, in arguments', function (done) { + it('should properly escape and ignore % and \\, in arguments', function () { var translator = Translator.create('en-GB'); var title = 'Test 1\\, 2\\, 3 % salmon'; var key = "[[topic:composer.replying_to, " + title + "]]"; - translator.translate(key).then(function (translated) { + return translator.translate(key).then(function (translated) { assert.strictEqual(translated, 'Replying to Test 1, 2, 3 % salmon'); - done(); }); }); - it('should not translate [[derp] some text', function (done) { + it('should not translate [[derp] some text', function () { var translator = Translator.create('en-GB'); - translator.translate('[[derp] some text').then(function (translated) { + return translator.translate('[[derp] some text').then(function (translated) { assert.strictEqual('[[derp] some text', translated); - done(); }); }); - it('should not translate [[derp:xyz] some text', function (done) { + it('should not translate [[derp:xyz] some text', function () { var translator = Translator.create('en-GB'); - translator.translate('[[derp:xyz] some text').then(function (translated) { + return translator.translate('[[derp:xyz] some text').then(function (translated) { assert.strictEqual('[[derp:xyz] some text', translated); - done(); }); }); - it('should translate [[pages:users/latest]] properly', function (done) { + it('should translate keys with slashes properly', function () { var translator = Translator.create('en-GB'); - translator.translate('[[pages:users/latest]]').then(function (translated) { + return translator.translate('[[pages:users/latest]]').then(function (translated) { assert.strictEqual(translated, 'Latest Users'); - done(); }); }); }); @@ -187,7 +171,7 @@ describe('Translator.create()', function () { }); describe('Translator modules', function () { - it('should work before registered', function (done) { + it('should work before registered', function () { var translator = Translator.create(); Translator.registerModule('test-custom-integer-format', function (lang) { @@ -206,20 +190,16 @@ describe('Translator modules', function () { }; }); - translator.translate('[[test-custom-integer-format:octal, 24]]') - .then(function (translation) { + return translator.translate('[[test-custom-integer-format:octal, 24]]').then(function (translation) { assert.strictEqual(translation, '30'); - done(); }); }); - it('should work after registered', function (done) { + it('should work after registered', function () { var translator = Translator.create('de'); - translator.translate('[[test-custom-integer-format:octal, 23]]') - .then(function (translation) { + return translator.translate('[[test-custom-integer-format:octal, 23]]').then(function (translation) { assert.strictEqual(translation, '27'); - done(); }); }); From a81aad61ab6e7c47f1460e20583cae7c469c68e5 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Thu, 1 Dec 2016 17:23:06 -0700 Subject: [PATCH 04/11] Add tests for translator static methods --- public/src/modules/translator.js | 6 ++++-- test/translator.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index e60385ed79..d975e16e1d 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -395,11 +395,13 @@ /** * Construct a translator pattern + * @param {string} name - Translation name + * @param {...string} arg - Optional argument for the pattern */ Translator.compile = function compile() { - var args = Array.prototype.slice.call(arguments, 0); + var args = Array.prototype.slice.call(arguments, 0); - return '[[' + args.join(', ') + ']]'; + return '[[' + args.join(', ') + ']]'; }; return Translator; diff --git a/test/translator.js b/test/translator.js index 60fb589e0d..a89681adef 100644 --- a/test/translator.js +++ b/test/translator.js @@ -223,4 +223,33 @@ describe('Translator static methods', function () { done(); }); }); + describe('.escape', function () { + it('should escape translation patterns within text', function (done) { + assert.strictEqual( + Translator.escape('some nice text [[global:home]] here'), + 'some nice text \\[\\[global:home\\]\\] here' + ); + done(); + }); + }); + + describe('.unescape', function () { + it('should unescape escaped translation patterns within text', function (done) { + assert.strictEqual( + Translator.unescape('some nice text \\[\\[global:home\\]\\] here'), + 'some nice text [[global:home]] here' + ); + done(); + }); + }); + + describe('.compile', function () { + it('should create a translator pattern from a key and list of arguments', function (done) { + assert.strictEqual( + Translator.compile('amazing:cool', 'awesome', 'great'), + '[[amazing:cool, awesome, great]]' + ); + done(); + }); + }); }); From bb5fe0cc8396bcecd2bb519a148d365ebc6f3a40 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Sat, 10 Dec 2016 20:41:49 -0700 Subject: [PATCH 05/11] Escape arguments in `Translator.compile` --- public/src/modules/translator.js | 7 +++++-- test/translator.js | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index d975e16e1d..30b67ef3a8 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -399,9 +399,12 @@ * @param {...string} arg - Optional argument for the pattern */ Translator.compile = function compile() { - var args = Array.prototype.slice.call(arguments, 0); + var args = Array.prototype.slice.call(arguments, 0).map(function (text) { + // escape commas and percent signs in arguments + return text.replace(/%/g, '%').replace(/,/g, ','); + }); - return '[[' + args.join(', ') + ']]'; + return '[[' + args.join(', ') + ']]'; }; return Translator; diff --git a/test/translator.js b/test/translator.js index a89681adef..8198814164 100644 --- a/test/translator.js +++ b/test/translator.js @@ -251,5 +251,13 @@ describe('Translator static methods', function () { ); done(); }); + + it('should escape `%` and `,` in arguments', function (done) { + assert.strictEqual( + Translator.compile('amazing:cool', '100% awesome!', 'one, two, and three'), + '[[amazing:cool, 100% awesome!, one, two, and three]]' + ); + done(); + }); }); }); From db1fdb897fbebdeb1ae334d562bf190c3f549614 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Sat, 10 Dec 2016 20:57:34 -0700 Subject: [PATCH 06/11] Fixes for dev-ing on windows - Change `nodebb.bat` to simply run `node ./nodebb` with same arguments - Fix `npm test` for windows --- nodebb.bat | 123 +-------------------------------------------------- package.json | 5 +-- 2 files changed, 3 insertions(+), 125 deletions(-) diff --git a/nodebb.bat b/nodebb.bat index d432dd3143..daaf09224f 100644 --- a/nodebb.bat +++ b/nodebb.bat @@ -1,122 +1 @@ -@echo off - -rem %1 action -rem %2 subaction - -setlocal enabledelayedexpansion -2>nul call :CASE_%1 -if ERRORLEVEL 1 call :DEFAULT_CASE - -exit /B - -:CASE_start - echo Starting NodeBB - echo "nodebb.bat stop" to stop the NodeBB server - echo "nodebb.bat log" to view server output - - rem Start the loader daemon - node loader %* - - goto END_CASE - -:CASE_stop - call :pidexists - if %_result%==0 ( - echo NodeBB is already stopped. - ) else ( - echo Stopping NodeBB. Goodbye! - - rem Doing this forcefully is probably not the best method - taskkill /PID !_pid! /f>nul - ) - - goto END_CASE - -:CASE_restart - echo Unsupported - - goto END_CASE - -:CASE_reload - echo Unsupported - - goto END_CASE - -:CASE_status - call :pidexists - if %_result%==0 ( - echo NodeBB is not running - echo "nodebb.bat start" to launch the NodeBB server - ) else ( - echo NodeBB Running ^(pid !_pid!^) - echo "nodebb.bat stop" to stop the NodeBB server - echo "nodebb.bat log" to view server output - echo "nodebb.bat restart" to restart NodeBB - ) - - goto END_CASE - -:CASE_log - cls - type .\logs\output.log - - goto END_CASE - -:CASE_upgrade - call npm install - call npm i nodebb-theme-vanilla nodebb-theme-lavender nodebb-widget-essentials - node app --upgrade - copy /b package.json +,,>nul - - goto END_CASE - -:CASE_setup - node app --setup %* - - goto END_CASE - -:CASE_reset - node app --reset --%2 - - goto END_CASE - -:CASE_dev - echo Launching NodeBB in "development" mode. - echo To run the production build of NodeBB, please use "forever". - echo More Information: https://docs.nodebb.org/en/latest/running/index.html - set NODE_ENV=development - node loader --no-daemon %* - - goto END_CASE - -:CASE_watch - echo Not supported - - goto END_CASE - -:DEFAULT_CASE - echo Welcome to NodeBB - echo Usage: nodebb.bat ^{start^|stop^|reload^|restart^|log^|setup^|reset^|upgrade^|dev^|watch^} - - goto END_CASE - -:END_CASE - endlocal - VER > NUL - goto :EOF - -:pidexists -if exist %~dp0pidfile ( - set /p _pid= Date: Sun, 11 Dec 2016 15:58:57 +0100 Subject: [PATCH 07/11] mongo: set scores as float instead of int --- src/database/mongo/sorted.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js index 11d4676b95..583794a380 100644 --- a/src/database/mongo/sorted.js +++ b/src/database/mongo/sorted.js @@ -17,7 +17,7 @@ module.exports = function (db, module) { value = helpers.valueToString(value); - db.collection('objects').update({_key: key, value: value}, {$set: {score: parseInt(score, 10)}}, {upsert:true, w: 1}, function (err) { + db.collection('objects').update({_key: key, value: value}, {$set: {score: parseFloat(score)}}, {upsert:true, w: 1}, function (err) { if (err && err.message.startsWith('E11000 duplicate key error')) { return process.nextTick(module.sortedSetAdd, key, score, value, callback); } @@ -38,7 +38,7 @@ module.exports = function (db, module) { var bulk = db.collection('objects').initializeUnorderedBulkOp(); for(var i = 0; i < scores.length; ++i) { - bulk.find({_key: key, value: values[i]}).upsert().updateOne({$set: {score: parseInt(scores[i], 10)}}); + bulk.find({_key: key, value: values[i]}).upsert().updateOne({$set: {score: parseFloat(scores[i])}}); } bulk.execute(function (err) { @@ -56,7 +56,7 @@ module.exports = function (db, module) { var bulk = db.collection('objects').initializeUnorderedBulkOp(); for(var i = 0; i < keys.length; ++i) { - bulk.find({_key: keys[i], value: value}).upsert().updateOne({$set: {score: parseInt(score, 10)}}); + bulk.find({_key: keys[i], value: value}).upsert().updateOne({$set: {score: parseFloat(score)}}); } bulk.execute(function (err) { @@ -564,7 +564,7 @@ module.exports = function (db, module) { } var data = {}; value = helpers.valueToString(value); - data.score = parseInt(increment, 10); + data.score = parseFloat(increment); db.collection('objects').findAndModify({_key: key, value: value}, {}, {$inc: data}, {new: true, upsert: true}, function (err, result) { // if there is duplicate key error retry the upsert From ec5d13188bf8939abc0b171b3e67f58b787a3ebb Mon Sep 17 00:00:00 2001 From: Moritz Schmidt Date: Sun, 11 Dec 2016 15:59:28 +0100 Subject: [PATCH 08/11] sneakily adjust database/sorted tests to include float scores --- test/database/sorted.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/database/sorted.js b/test/database/sorted.js index dc57c8e0e0..ac95fcbe09 100644 --- a/test/database/sorted.js +++ b/test/database/sorted.js @@ -10,7 +10,7 @@ describe('Sorted Set methods', function () { before(function (done) { async.parallel([ function (next) { - db.sortedSetAdd('sortedSetTest1', [1, 2, 3], ['value1', 'value2', 'value3'], next); + db.sortedSetAdd('sortedSetTest1', [1.1, 1.2, 1.3], ['value1', 'value2', 'value3'], next); }, function (next) { db.sortedSetAdd('sortedSetTest2', [1, 4], ['value1', 'value4'], next); @@ -97,7 +97,7 @@ describe('Sorted Set methods', function () { db.getSortedSetRangeWithScores('sortedSetTest1', 0, -1, function (err, values) { assert.equal(err, null); assert.equal(arguments.length, 2); - assert.deepEqual(values, [{value: 'value1', score: 1}, {value: 'value2', score: 2}, {value: 'value3', score: 3}]); + assert.deepEqual(values, [{value: 'value1', score: 1.1}, {value: 'value2', score: 1.2}, {value: 'value3', score: 1.3}]); done(); }); }); @@ -108,7 +108,7 @@ describe('Sorted Set methods', function () { db.getSortedSetRevRangeWithScores('sortedSetTest1', 0, -1, function (err, values) { assert.equal(err, null); assert.equal(arguments.length, 2); - assert.deepEqual(values, [{value: 'value3', score: 3}, {value: 'value2', score: 2}, {value: 'value1', score: 1}]); + assert.deepEqual(values, [{value: 'value3', score: 1.3}, {value: 'value2', score: 1.2}, {value: 'value1', score: 1.1}]); done(); }); }); @@ -116,7 +116,7 @@ describe('Sorted Set methods', function () { describe('getSortedSetRangeByScore()', function () { it('should get count elements with score between min max sorted by score lowest to highest', function (done) { - db.getSortedSetRangeByScore('sortedSetTest1', 0, -1, '-inf', 2, function (err, values) { + db.getSortedSetRangeByScore('sortedSetTest1', 0, -1, '-inf', 1.2, function (err, values) { assert.equal(err, null); assert.equal(arguments.length, 2); assert.deepEqual(values, ['value1', 'value2']); @@ -127,7 +127,7 @@ describe('Sorted Set methods', function () { describe('getSortedSetRevRangeByScore()', function () { it('should get count elements with score between max min sorted by score highest to lowest', function (done) { - db.getSortedSetRevRangeByScore('sortedSetTest1', 0, -1, '+inf', 2, function (err, values) { + db.getSortedSetRevRangeByScore('sortedSetTest1', 0, -1, '+inf', 1.2, function (err, values) { assert.equal(err, null); assert.equal(arguments.length, 2); assert.deepEqual(values, ['value3', 'value2']); @@ -138,10 +138,10 @@ describe('Sorted Set methods', function () { describe('getSortedSetRangeByScoreWithScores()', function () { it('should get count elements with score between min max sorted by score lowest to highest with scores', function (done) { - db.getSortedSetRangeByScoreWithScores('sortedSetTest1', 0, -1, '-inf', 2, function (err, values) { + db.getSortedSetRangeByScoreWithScores('sortedSetTest1', 0, -1, '-inf', 1.2, function (err, values) { assert.equal(err, null); assert.equal(arguments.length, 2); - assert.deepEqual(values, [{value: 'value1', score: 1}, {value: 'value2', score: 2}]); + assert.deepEqual(values, [{value: 'value1', score: 1.1}, {value: 'value2', score: 1.2}]); done(); }); }); @@ -149,10 +149,10 @@ describe('Sorted Set methods', function () { describe('getSortedSetRevRangeByScoreWithScores()', function () { it('should get count elements with score between max min sorted by score highest to lowest', function (done) { - db.getSortedSetRevRangeByScoreWithScores('sortedSetTest1', 0, -1, '+inf', 2, function (err, values) { + db.getSortedSetRevRangeByScoreWithScores('sortedSetTest1', 0, -1, '+inf', 1.2, function (err, values) { assert.equal(err, null); assert.equal(arguments.length, 2); - assert.deepEqual(values, [{value: 'value3', score: 3}, {value: 'value2', score: 2}]); + assert.deepEqual(values, [{value: 'value3', score: 1.3}, {value: 'value2', score: 1.2}]); done(); }); }); @@ -169,7 +169,7 @@ describe('Sorted Set methods', function () { }); it('should return number of elements between scores min max inclusive', function (done) { - db.sortedSetCount('sortedSetTest1', '-inf', 2, function (err, count) { + db.sortedSetCount('sortedSetTest1', '-inf', 1.2, function (err, count) { assert.equal(err, null); assert.equal(arguments.length, 2); assert.equal(count, 2); @@ -321,7 +321,7 @@ describe('Sorted Set methods', function () { db.sortedSetScore('sortedSetTest1', 'value2', function (err, score) { assert.equal(err, null); assert.equal(arguments.length, 2); - assert.equal(score, 2); + assert.equal(score, 1.2); done(); }); }); @@ -332,7 +332,7 @@ describe('Sorted Set methods', function () { db.sortedSetsScore(['sortedSetTest1', 'sortedSetTest2', 'doesnotexist'], 'value1', function (err, scores) { assert.equal(err, null); assert.equal(arguments.length, 2); - assert.deepEqual(scores, [1, 1, null]); + assert.deepEqual(scores, [1.1, 1, null]); done(); }); }); @@ -355,7 +355,7 @@ describe('Sorted Set methods', function () { db.sortedSetScores('sortedSetTest1', ['value2', 'value1', 'doesnotexist'], function (err, scores) { assert.equal(err, null); assert.equal(arguments.length, 2); - assert.deepEqual(scores, [2, 1, null]); + assert.deepEqual(scores, [1.2, 1.1, null]); done(); }); }); From b1a48981ef127e8e9eaff6bbff1418de07967666 Mon Sep 17 00:00:00 2001 From: Mathias Schreck Date: Mon, 12 Dec 2016 17:08:21 +0100 Subject: [PATCH 09/11] Check if href exists before accessing it (#5281) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I got a lot of errors in Firefox 50 `TypeError: $(...).attr(...) is undefined nodebb.min.js:25167:24` which points exactly to that line I’ve changed. Since HTML5 `href` is not a required attribute of an `a` tag. We have a couple of links without `href` and every time you click it you will get this error. --- public/src/ajaxify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index a990e08757..3c59b54408 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -366,7 +366,7 @@ $(document).ready(function () { } // Default behaviour for rss feeds - if (internalLink && $(this).attr('href').endsWith('.rss')) { + if (internalLink && $(this).attr('href') && $(this).attr('href').endsWith('.rss')) { return; } From 0a4e45c0da7efde86367c39ec80051737aff2336 Mon Sep 17 00:00:00 2001 From: pichalite Date: Tue, 13 Dec 2016 01:18:42 +0000 Subject: [PATCH 10/11] Check password length on setup --- src/install.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/install.js b/src/install.js index acf7aadc97..910fd8c46b 100644 --- a/src/install.js +++ b/src/install.js @@ -220,9 +220,10 @@ function createAdministrator(next) { } function createAdmin(callback) { - var User = require('./user'), - Groups = require('./groups'), - password; + var User = require('./user'); + var Groups = require('./groups'); + var password; + var meta = require('./meta'); winston.warn('No administrators have been detected, running initial user setup\n'); @@ -262,6 +263,12 @@ function createAdmin(callback) { winston.warn("Passwords did not match, please try again"); return retryPassword(results); } + + if (results.password.length < meta.config.minimumPasswordLength) { + winston.warn("Password too short, please try again"); + return retryPassword(results); + } + var adminUid; async.waterfall([ function (next) { From aea08d58b1a75b07c4de5aada230dc1efe6d6337 Mon Sep 17 00:00:00 2001 From: Anil Mandepudi Date: Mon, 12 Dec 2016 17:19:59 -0800 Subject: [PATCH 11/11] Fix tabs --- src/install.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/install.js b/src/install.js index 910fd8c46b..8c14302d80 100644 --- a/src/install.js +++ b/src/install.js @@ -221,8 +221,8 @@ function createAdministrator(next) { function createAdmin(callback) { var User = require('./user'); - var Groups = require('./groups'); - var password; + var Groups = require('./groups'); + var password; var meta = require('./meta'); winston.warn('No administrators have been detected, running initial user setup\n');