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

Nunjucks enclosed by two backtick-delimited strings fails. #2563

Closed
jo4x962k7JL opened this issue May 13, 2017 · 3 comments
Closed

Nunjucks enclosed by two backtick-delimited strings fails. #2563

jo4x962k7JL opened this issue May 13, 2017 · 3 comments
Labels
bug Something isn't working

Comments

@jo4x962k7JL
Copy link

e.g.

`backtick test1`
{% blockquote %}
Blockquoe test1
{% endblockquote %}

`backtick test2`
{% blockquote %}
Blockquoe test2
{% endblockquote %}

will get the result like:
2017-05-13 11 10 05

Any idea to solve this?

@NoahDragon
Copy link
Member

This is definitely something need to be fixed.

@lijxug
Copy link

lijxug commented May 14, 2017

I encountered the same bug while using {% asset_img img.jpg %}

@seaoak
Copy link
Member

seaoak commented May 16, 2017

I found that this issue is caused by a latent bug.

The Pull Request #2461 (commit 5134cba) made the bug easier to be realized.

To fix the bug, change a regexp to be non-greedy.

https://github.com/hexojs/hexo/blob/master/lib/extend/tag.js#L65

diff --git a/lib/extend/tag.js b/lib/extend/tag.js
index 1222b01..372bd9c 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(/(?:<pre>)?<code.*>[\s\S]*?<\/code>(?:<\/pre>)?/gm, escapeContent);
+    str = str.replace(/(?:<pre>)?<code.*?>[\s\S]*?<\/code>(?:<\/pre>)?/gm, escapeContent);
     env.renderString(str, options, function(err, result) {
       if (err) return reject(err);
       resolve(result.replace(rPlaceholder, function() {

I will add test cases, and make a pull request.

@NoahDragon NoahDragon added bug Something isn't working and removed need-verify labels May 16, 2017
@NoahDragon NoahDragon mentioned this issue May 16, 2017
5 tasks
seaoak added a commit to seaoak/hexo that referenced this issue May 17, 2017
seaoak added a commit to seaoak/hexo that referenced this issue May 17, 2017
NoahDragon added a commit that referenced this issue May 23, 2017
NoahDragon added a commit that referenced this issue May 24, 2017
* Revert "Update package.json"

This reverts commit a7e85aa.

* Revert "3.3.6"

This reverts commit 3c84b67.

* Revert "Fix parsing error about <code> tag (Issue #2563) (#2568)"

This reverts commit 7f933d4.

* Update tag.js

* Update tag.js

* Update post.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants