From 7c9d48af32205509cae2284fdadef7084f8107b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=8D=C9=AA=E1=B4=8D=C9=AA?= <1119186082@qq.com> Date: Wed, 26 Feb 2020 23:03:22 +0800 Subject: [PATCH 1/2] fix(post): use non-greedy regular expressions --- lib/hexo/post.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hexo/post.js b/lib/hexo/post.js index fc0ac7cc81..1d62074eca 100644 --- a/lib/hexo/post.js +++ b/lib/hexo/post.js @@ -43,7 +43,7 @@ class PostRenderCache { const rSwigVar = /\{\{[\s\S]*?\}\}/g; const rSwigComment = /\{#[\s\S]*?#\}/g; const rSwigBlock = /\{%[\s\S]*?%\}/g; - const rSwigFullBlock = /\{% *(.+?)(?: *| +.*)%\}[\s\S]+?\{% *end\1 *%\}/g; + const rSwigFullBlock = /\{% *(.+?)(?: *| +.*?)%\}[\s\S]+?\{% *end\1 *%\}/g; const escape = _str => _escapeContent(this.cache, _str); return str.replace(rSwigFullBlock, escape) From 49617850ef3ff74fa65349516e97d85b182b5662 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 27 Feb 2020 14:19:41 +0800 Subject: [PATCH 2/2] add related test cases --- test/scripts/hexo/post.js | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/scripts/hexo/post.js b/test/scripts/hexo/post.js index ce236f8019..a02b8b4a8e 100644 --- a/test/scripts/hexo/post.js +++ b/test/scripts/hexo/post.js @@ -888,4 +888,48 @@ describe('Post', () => { }); }); + // test for PR #4161 + it('render() - adjacent tags', () => { + const content = [ + '{% pullquote %}content1{% endpullquote %}', + '', + 'This is a following paragraph', + '', + '{% pullquote %}content2{% endpullquote %}' + ].join('\n'); + + return post.render(null, { + content, + engine: 'markdown' + }).then(data => { + data.content.trim().should.eql([ + '
\n', + 'content1
\n
This is a following paragraph
\n', + '\n' + ].join('')); + }); + }); + + // test for PR #4161 + it('render() - adjacent tags with args', () => { + const content = [ + '{% pullquote center %}content1{% endpullquote %}', + '', + 'This is a following paragraph', + '', + '{% pullquote center %}content2{% endpullquote %}' + ].join('\n'); + + return post.render(null, { + content, + engine: 'markdown' + }).then(data => { + data.content.trim().should.eql([ + 'content2
\n
\n', + 'content1
\n
This is a following paragraph
\n', + '\n' + ].join('')); + }); + }); + });content2
\n