improve trimming bad inputs and fix code block markdown to be non-greedy and respect first line leading whitespace

merge-requests/208/head
fatchan 5 years ago
parent de953fd8cf
commit c18f25861e
  1. 2
      helpers/paramconverter.js
  2. 4
      helpers/posting/markdown.js

@ -24,7 +24,7 @@ module.exports = (req, res, next) => {
for (let i = 0; i < trimFields.length; i++) {
const field = trimFields[i];
if (req.body[field]) {
req.body[field] = req.body[field].trim();
req.body[field] = req.body[field].trimEnd();
}
}

@ -11,7 +11,7 @@ const Posts = require(__dirname+'/../../db/posts.js')
, linkRegex = /https?\:\/\/[^\s<>\[\]{}|\\^]+/g
, spoilerRegex = /\|\|(.+)\|\|/gm
, detectedRegex = /(\(\(\(.+\)\)\))/gm
, codeRegex = /^```\s([\s\S]+)\s```/gm;
, codeRegex = /```([\s\S]+?)```/gm;
module.exports = (text) => {
@ -67,7 +67,7 @@ module.exports = (text) => {
//code
text = text.replace(codeRegex, (match, code) => {
return `<span class='code'>${code.trim()}</span>`;
return `<span class='code'>${code.replace(/^\s*\n/, '')}</span>`;
});
//detected

Loading…
Cancel
Save