From 9edbc9971f565d9021f765794a93fa33dd6e1d21 Mon Sep 17 00:00:00 2001 From: Sukka Date: Fri, 1 Oct 2021 21:30:35 +0800 Subject: [PATCH] fix(#4780): empty tag name correction (#4786) --- lib/hexo/post.js | 2 +- test/scripts/hexo/post.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/hexo/post.js b/lib/hexo/post.js index 9db255d437..462f650ffc 100644 --- a/lib/hexo/post.js +++ b/lib/hexo/post.js @@ -102,7 +102,7 @@ class PostRenderEscape { } else if (state === STATE_SWIG_TAG) { if (char === '%' && next_char === '}') { // From swig back to plain text idx++; - if (str.includes(`end${swig_tag_name}`)) { + if (swig_tag_name !== '' && str.includes(`end${swig_tag_name}`)) { state = STATE_SWIG_FULL_TAG; } else { swig_tag_name = ''; diff --git a/test/scripts/hexo/post.js b/test/scripts/hexo/post.js index c9fdbc6060..ccedb78a82 100644 --- a/test/scripts/hexo/post.js +++ b/test/scripts/hexo/post.js @@ -1357,4 +1357,22 @@ describe('Post', () => { hexo.config.prismjs.enable = false; hexo.config.highlight.enable = true; }); + + it('render() - empty tag name', async () => { + hexo.config.prismjs.enable = true; + hexo.config.highlight.enable = false; + + const content = 'Disable rendering of Nunjucks tag `{{ }}` / `{% %}`'; + + const data = await post.render(null, { + content, + engine: 'markdown' + }); + + data.content.should.include(escapeSwigTag('{{ }}')); + data.content.should.include(escapeSwigTag('{% %}')); + + hexo.config.prismjs.enable = false; + hexo.config.highlight.enable = true; + }); });