hexojs / hexojs/hexo

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

Open
#5,635 2 comments 0 reactions 0 assignees Claimed by @zombie12138 View on GitHub
bug
Dominant language
TypeScript
Stars
41.8k
Forks
41
PR merge metrics
No merged PRs in 30d

Description

### Check List

- [x] I have already read [Docs page](https://hexo.io/docs/) & [Troubleshooting page](https://hexo.io/docs/troubleshooting).
- [x] I have already searched existing issues and they are not help to me.
- [x] I examined error or warning messages and it's difficult to solve.
- [x] I am using the [latest](https://github.com/hexojs/hexo/releases) version of Hexo. (run `hexo version` to check)
- [x] My Node.js is matched [the required version](https://hexo.io/docs/#Required-Node-js-version).

### Expected behavior

The Post:

```md
---
title: Hello World
date: 2021-10-09 21:50:25
refplus: true
---

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?

```bash
sudo apt install npm
sudo npm install hexo@7.3.0 -g
hexo init testenv
cd testenv
npm install hexo-reference-plus
cd source/_posts/
tee >hello-world.md <
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

```text
v18.19.1
9.2.0
```

### Your Hexo and Plugin version

```text
hexo-site@0.0.0 /home/admin/test/testenv
├── 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
└── hexo@7.3.0
```

### Your `package.json`

```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)

```yaml

```

### 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.