Skip to content

Commit

Permalink
fix(post): non-greedy regexp for swig escape (#4161)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang authored Feb 27, 2020
1 parent a97bd2f commit a9fb3fd
Show file tree
Hide file tree
Showing 2 changed files with 45 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 @@ -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)
Expand Down
44 changes: 44 additions & 0 deletions test/scripts/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
'<blockquote class="pullquote"><p>content1</p>\n</blockquote>\n',
'<p>This is a following paragraph</p>\n',
'<blockquote class="pullquote"><p>content2</p>\n</blockquote>\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([
'<blockquote class="pullquote center"><p>content1</p>\n</blockquote>\n',
'<p>This is a following paragraph</p>\n',
'<blockquote class="pullquote center"><p>content2</p>\n</blockquote>\n'
].join(''));
});
});

});

0 comments on commit a9fb3fd

Please sign in to comment.