From 71ac13fa6dcbab917e5985663c9bd4703fa5cada Mon Sep 17 00:00:00 2001 From: uiolee <22849383+uiolee@users.noreply.github.com> Date: Sat, 20 Jan 2024 19:24:08 +0800 Subject: [PATCH] fix(escapeTags): escape tag which includes line break --- lib/hexo/post.ts | 2 +- test/scripts/hexo/post.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/hexo/post.ts b/lib/hexo/post.ts index 0d6810a50e..790a540663 100644 --- a/lib/hexo/post.ts +++ b/lib/hexo/post.ts @@ -69,7 +69,7 @@ class PostRenderEscape { * @returns string */ escapeAllSwigTags(str: string) { - if (!/(\{\{.+?\}\})|(\{#.+?#\})|(\{%.+?%\})/.test(str)) { + if (!/(\{\{.+?\}\})|(\{#.+?#\})|(\{%.+?%\})/s.test(str)) { return str; } let state = STATE_PLAINTEXT; diff --git a/test/scripts/hexo/post.js b/test/scripts/hexo/post.js index cf7dd423b2..109bf2367b 100644 --- a/test/scripts/hexo/post.js +++ b/test/scripts/hexo/post.js @@ -1396,4 +1396,22 @@ describe('Post', () => { should.fail(); } catch (err) {} }); + + // https://github.com/hexojs/hexo/issues/5401 + it('render() - tags in different lines', async () => { + const content = [ + '{% link', + 'foobar', + 'https://hexo.io/', + 'tttitle', + '%}' + ].join('\n'); + + const data = await post.render(null, { + content, + engine: 'markdown' + }); + + data.content.should.eql('foobar'); + }); });