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

Markdown text is escaped when two tags share the same prefix. #5635

Open
5 tasks done
zombie12138 opened this issue Feb 20, 2025 · 2 comments · May be fixed by #5636
Open
5 tasks done

Markdown text is escaped when two tags share the same prefix. #5635

zombie12138 opened this issue Feb 20, 2025 · 2 comments · May be fixed by #5636

Comments

@zombie12138
Copy link

Check List

  • I have already read Docs page & Troubleshooting page.
  • I have already searched existing issues and they are not help to me.
  • I examined error or warning messages and it's difficult to solve.
  • I am using the latest version of Hexo. (run hexo version to check)
  • My Node.js is matched the required version.

Expected behavior

The Post:

---
title: Hello World
date: 2021-10-09 21:50:25
refplus: true
---
<!-- more -->
Test {% ref self %}.
## Ref
{% references %}
[self] {% post_link hello-world hello-world %}
{% endreferences %}

All Markdown content between the ref and endreferences tags is rendered properly. And ## Ref is rendered as an h2 element.

Actual behavior

All Markdown content between the ref and endreferences tags is escaped, resulting in unrendered text.

Image

How to reproduce?

sudo apt install npm
sudo npm install [email protected] -g
hexo init testenv
cd testenv
npm install hexo-reference-plus
cd source/_posts/
tee >hello-world.md  <<EOF
---
title: Hello World
date: 2021-10-09 21:50:25
refplus: true
---
<!-- more -->
Test {% ref self %}.
## Ref
{% references %}
[self] {% post_link hello-world hello-world %}
{% endreferences %}
EOF

Is the problem still there under Safe mode?

Yes

Your Node.js & npm version

v18.19.1
9.2.0

Your Hexo and Plugin version

[email protected] /home/admin/test/testenv
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Your package.json

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "build": "hexo generate",
    "clean": "hexo clean",
    "deploy": "hexo deploy",
    "server": "hexo server"
  },
  "hexo": {
    "version": "7.3.0"
  },
  "dependencies": {
    "hexo": "^7.3.0",
    "hexo-generator-archive": "^2.0.0",
    "hexo-generator-category": "^2.0.0",
    "hexo-generator-index": "^4.0.0",
    "hexo-generator-tag": "^2.0.0",
    "hexo-reference-plus": "^1.1.0",
    "hexo-renderer-ejs": "^2.0.0",
    "hexo-renderer-marked": "^7.0.0",
    "hexo-renderer-stylus": "^3.0.1",
    "hexo-server": "^3.0.0",
    "hexo-theme-landscape": "^1.0.0"
  }
}

Your site's _config.yml (Optional)

Others

I discovered this bug is caused by the escapeAllSwigTags function:

The ref and references tags share the same prefix. When escapeAllSwigTags uses endref to identify block-level tags, all content between {% ref xxx %} and {% endreferences %} is incorrectly escaped, resulting in unrendered Markdown.

This is clearly a bug:

  1. The tag plugin functioned correctly with Hexo four years ago.
  2. Plugins are restricted from sharing prefixes, and patterns like end${plugin_name} in text will also cause ambiguity.
zombie12138 added a commit to zombie12138/hexo that referenced this issue Feb 20, 2025
zombie12138 added a commit to zombie12138/hexo that referenced this issue Feb 20, 2025
@zombie12138
Copy link
Author

zombie12138 commented Feb 20, 2025

I would like to address this issue by contributing code to Hexo. I have proposed two solutions:

  1. Maintain a registry table during tag registration to determine if a tag is block-level. Implementation details can be found in my branch.
  2. Use stricter regex matching for end tags (e.g., /{%\s*end([\w_]+)\s*%}/g;). This approach is implemented in my branch.

Please indicate the preferred solution, and I will submit a corresponding PR. I welcome any feedback to refine these approaches.

zombie12138 added a commit to zombie12138/hexo that referenced this issue Feb 20, 2025
zombie12138 added a commit to zombie12138/hexo that referenced this issue Feb 20, 2025
@D-Sketon
Copy link
Member

I'm not sure which one is better, but there isn't much difference between these two in terms of performance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants