mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
fixes #4653
This commit is contained in:
@@ -1,10 +1,14 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var nconf = require('nconf'),
|
||||||
|
url = require('url');
|
||||||
|
|
||||||
var cache = require('./cache');
|
var cache = require('./cache');
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var translator = require('../../public/src/modules/translator');
|
var translator = require('../../public/src/modules/translator');
|
||||||
|
|
||||||
|
var urlRegex = /href="([^"]+)"/g;
|
||||||
|
|
||||||
module.exports = function(Posts) {
|
module.exports = function(Posts) {
|
||||||
|
|
||||||
Posts.parsePost = function(postData, callback) {
|
Posts.parsePost = function(postData, callback) {
|
||||||
@@ -26,6 +30,7 @@ module.exports = function(Posts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.postData.content = translator.escape(data.postData.content);
|
data.postData.content = translator.escape(data.postData.content);
|
||||||
|
data.postData.content = Posts.relativeToAbsolute(data.postData.content);
|
||||||
|
|
||||||
if (global.env === 'production' && data.postData.pid) {
|
if (global.env === 'production' && data.postData.pid) {
|
||||||
cache.set(data.postData.pid, data.postData.content);
|
cache.set(data.postData.pid, data.postData.content);
|
||||||
@@ -40,4 +45,29 @@ module.exports = function(Posts) {
|
|||||||
|
|
||||||
plugins.fireHook('filter:parse.signature', {userData: userData, uid: uid}, callback);
|
plugins.fireHook('filter:parse.signature', {userData: userData, uid: uid}, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Posts.relativeToAbsolute = function(content) {
|
||||||
|
// Turns relative links in post body to absolute urls
|
||||||
|
var parsed, current, absolute;
|
||||||
|
|
||||||
|
while ((current=urlRegex.exec(content)) !== null) {
|
||||||
|
if (current[1]) {
|
||||||
|
parsed = url.parse(current[1]);
|
||||||
|
|
||||||
|
if (!parsed.protocol) {
|
||||||
|
if (current[1].startsWith('/')) {
|
||||||
|
// Internal link
|
||||||
|
absolute = nconf.get('url') + current[1];
|
||||||
|
} else {
|
||||||
|
// External link
|
||||||
|
absolute = '//' + current[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
content = content.slice(0, current.index + 6) + absolute + content.slice(current.index + 6 + current[1].length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ module.exports = function(Topics) {
|
|||||||
pid: postData.pid,
|
pid: postData.pid,
|
||||||
subject: '[' + (meta.config.title || 'NodeBB') + '] ' + title,
|
subject: '[' + (meta.config.title || 'NodeBB') + '] ' + title,
|
||||||
intro: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + titleEscaped + ']]',
|
intro: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + titleEscaped + ']]',
|
||||||
postBody: postData.content.replace(/"\/\//g, '"http://'),
|
postBody: postData.content.replace(/"\/\//g, '"https://'),
|
||||||
site_title: meta.config.title || 'NodeBB',
|
site_title: meta.config.title || 'NodeBB',
|
||||||
username: data.userData.username,
|
username: data.userData.username,
|
||||||
userslug: data.userData.userslug,
|
userslug: data.userData.userslug,
|
||||||
|
|||||||
Reference in New Issue
Block a user