From 5134cba97bed6ea83f1695bf054f08dc3f5f72ac Mon Sep 17 00:00:00 2001 From: Haoliang Gao Date: Thu, 13 Apr 2017 01:09:18 +0800 Subject: [PATCH] Fix error when tag.render (#2461) --- lib/extend/tag.js | 2 +- test/scripts/extend/tag.js | 16 ++++++++++++++++ test/scripts/hexo/post.js | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/extend/tag.js b/lib/extend/tag.js index 01373f28d7..1222b01fc2 100644 --- a/lib/extend/tag.js +++ b/lib/extend/tag.js @@ -62,7 +62,7 @@ Tag.prototype.render = function(str, options, callback) { var env = this.env; return new Promise(function(resolve, reject) { - str = str.replace(/
[\s\S]*?<\/code><\/pre>/gm, escapeContent);
+    str = str.replace(/(?:
)?[\s\S]*?<\/code>(?:<\/pre>)?/gm, escapeContent);
     env.renderString(str, options, function(err, result) {
       if (err) return reject(err);
       resolve(result.replace(rPlaceholder, function() {
diff --git a/test/scripts/extend/tag.js b/test/scripts/extend/tag.js
index db0a76cb32..a7c2604f9d 100644
--- a/test/scripts/extend/tag.js
+++ b/test/scripts/extend/tag.js
@@ -148,4 +148,20 @@ describe('Tag', () => {
       result.should.eql('bar');
     });
   });
+
+  it('render() - ignore 
', function() {
+    var str = '
{{ helper.json() }}
'; + + return tag.render(str).then(function(result) { + result.should.eql(str); + }); + }); + + it('render() - ignore ', function() { + var str = '{{ helper.json() }}'; + + return tag.render(str).then(function(result) { + result.should.eql(str); + }); + }); }); diff --git a/test/scripts/hexo/post.js b/test/scripts/hexo/post.js index d484bc9ce7..a2da89ce91 100644 --- a/test/scripts/hexo/post.js +++ b/test/scripts/hexo/post.js @@ -640,7 +640,7 @@ describe('Post', () => { content, engine: 'markdown' }).then(data => { - data.content.trim().should.eql('

{{ test }}

'); + data.content.trim().should.eql('

{% raw %}{{ test }}{% endraw %}

'); }); }); @@ -648,7 +648,7 @@ describe('Post', () => { var content = '`{% raw %}{{ test }}{% endraw %}`'; var filter = sinon.spy(result => { - result.trim().should.eql('

{{ test }}

'); + result.trim().should.eql('

{% raw %}{{ test }}{% endraw %}

'); }); hexo.extend.filter.register('after_render:html', filter);