v1.18.x
barisusakli 8 years ago
commit 82d3b24cd3

@ -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=<pidfile
for /f "usebackq" %%Z in (`tasklist /nh /fi "PID eq !_pid!"`) do (
if %%Z==INFO: (
del pidfile
set _result=0
) else (
set _result=1
)
)
) else (
set _result=0
)
node ./nodebb %*

@ -13,9 +13,8 @@
"start": "node loader.js",
"lint": "eslint --cache .",
"pretest": "npm run lint",
"test": "istanbul cover _mocha test",
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"test-windows": "_mocha test"
"test": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec",
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
"dependencies": {
"async": "~1.5.0",

@ -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;
}

@ -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, '&#37;').replace(/\\,/g, '&#44;');
out = out.replace(new RegExp('%' + (i + 1), 'g'), escaped);
});
return out;
});
@ -394,9 +395,14 @@
/**
* 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).map(function (text) {
// escape commas and percent signs in arguments
return text.replace(/%/g, '&#37;').replace(/,/g, '&#44;');
});
return '[[' + args.join(', ') + ']]';
};

@ -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

@ -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);
});
};

@ -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) {

@ -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();
});
});

@ -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,139 +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, '<strong>Guest</strong> has posted a reply to: <strong>My Topic</strong>');
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, '<strong>Guest</strong> has posted a reply to: <strong>Guest</strong>');
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, <strong>test</strong>]]';
translator.translate(key).then(function (translated) {
return translator.translate(key).then(function (translated) {
assert.strictEqual(translated, 'Perhaps you should <a href=\'&lt;strong&gt;test&lt;/strong&gt;/login\'>try logging in</a>?');
done();
});
});
it('should properly escape % and ,', 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';
title = title.replace(/%/g, '&#37;').replace(/,/g, '&#44;');
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');
done();
return translator.translate(key).then(function (translated) {
assert.strictEqual(translated, 'Replying to Test 1&#44; 2&#44; 3 &#37; salmon');
});
});
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();
});
});
});
@ -188,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) {
@ -207,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();
});
});
@ -244,4 +223,41 @@ 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();
});
it('should escape `%` and `,` in arguments', function (done) {
assert.strictEqual(
Translator.compile('amazing:cool', '100% awesome!', 'one, two, and three'),
'[[amazing:cool, 100&#37; awesome!, one&#44; two&#44; and three]]'
);
done();
});
});
});

Loading…
Cancel
Save