Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(post): use non-greedy regular expressions #4161

Merged
merged 2 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(''));
});
});

});