From b67232fc3f04c1965691a696242df29b3e3e999a Mon Sep 17 00:00:00 2001 From: Thomas Lynch Date: Sat, 28 Jan 2023 14:29:55 +1100 Subject: [PATCH] rename escape to simpleEscape to prevent ever accidentally colliding with global escape --- lib/post/markdown/escape.test.js | 6 +++--- lib/post/markdown/markdown.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/post/markdown/escape.test.js b/lib/post/markdown/escape.test.js index 4c03bc15..9f68f547 100644 --- a/lib/post/markdown/escape.test.js +++ b/lib/post/markdown/escape.test.js @@ -1,6 +1,6 @@ -const escape = require('./escape.js'); +const simpleEscape = require('./escape.js'); -describe('escape() - convert some characters to html entities', () => { +describe('simpleEscape() - convert some characters to html entities', () => { const cases = [ { in: '\'', out: ''' }, { in: '/', out: '/' }, @@ -13,7 +13,7 @@ describe('escape() - convert some characters to html entities', () => { ]; for(let i in cases) { test(`should output ${cases[i].out} for an input of ${cases[i].in}`, () => { - expect(escape(cases[i].in)).toBe(cases[i].out); + expect(simpleEscape(cases[i].in)).toBe(cases[i].out); }); } }); diff --git a/lib/post/markdown/markdown.js b/lib/post/markdown/markdown.js index 2e58c1c8..dadbdb1f 100644 --- a/lib/post/markdown/markdown.js +++ b/lib/post/markdown/markdown.js @@ -16,7 +16,7 @@ const greentextRegex = /^>((?!>\d+|>>/\w+(/\d*)?|>># , includeSplitRegex = /(\[code\][\s\S]+?\[\/code\])/gm , splitRegex = /\[code\]([\s\S]+?)\[\/code\]/gm , trimNewlineRegex = /^(\s*\r?\n)*/g - , escape = require(__dirname+'/escape.js') + , simpleEscape = require(__dirname+'/escape.js') , { highlight, highlightAuto, listLanguages } = require('highlight.js') , validLanguages = listLanguages() //precompute , { addCallback } = require(__dirname+'/../../redis/redis.js') @@ -72,7 +72,7 @@ module.exports = { for (let i = 0; i < chunks.length; i++) { //every other chunk will be a code block if (i % 2 === 0) { - const escaped = escape(chunks[i]); + const escaped = simpleEscape(chunks[i]); const newlineFix = escaped.replace(/^\r?\n/,''); //fix ending newline because of codeblock chunks[i] = module.exports.processRegularChunk(newlineFix, permissions); } else if (permissions.get(Permissions.USE_MARKDOWN_CODE)){ @@ -96,13 +96,13 @@ module.exports = { return `possible language: ${language}, relevance: ${relevance}\n${value}`; } } else if (lang === 'aa') { - return `${escape(matches.groups.code)}`; + return `${simpleEscape(matches.groups.code)}`; } else if (validLanguages.includes(lang)) { const { value } = highlight(trimFix, { language: lang, ignoreIllegals: true }); return `language: ${lang}\n${value}`; } //else, auto highlight relevance threshold was too low, lang was not a valid language, or lang was 'plain' - return `${escape(trimFix)}`; + return `${simpleEscape(trimFix)}`; }, processRegularChunk: (text, permissions) => {