Skip to content

Commit

Permalink
fix(#4780): empty tag name correction (#4786)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Oct 1, 2021
1 parent b56ba65 commit 9edbc99
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
18 changes: 18 additions & 0 deletions test/scripts/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});

0 comments on commit 9edbc99

Please sign in to comment.