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(escapeAllSwigTags): Prevent swig tag prefix collision during esca… #5636

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zombie12138
Copy link

@zombie12138 zombie12138 commented Feb 23, 2025

What does it do?

fix bug in #5635

When a non-block Swig tag (Tag A) shares a prefix for a block-level tag (Tag B), such as non-block ref tag and block-level references tag, escapeAllSwigTags will mistakenly identify tag A (ref in my case) as a block-level tag, and escape all content between {% tag %} and {% endreferences %}, leading to unrendered content.

This pull request resolves this case by implementing a block tag registry table. This methodology achieves maximum precision, but it introduces increased code coupling as an implementation trade-off.

Screenshots

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

Sorry, something went wrong.

Copy link

How to test

git clone -b hotfix/swig-tag-conflict https://github.com/zombie12138/hexo.git
cd hexo
npm install
npm test

@zombie12138 zombie12138 force-pushed the hotfix/swig-tag-conflict branch from 9d0b5e9 to 5483a3b Compare February 23, 2025 16:37
@D-Sketon D-Sketon linked an issue Feb 24, 2025 that may be closed by this pull request
5 tasks
@coveralls
Copy link

coveralls commented Feb 24, 2025

Pull Request Test Coverage Report for Build 14007045798

Details

  • 17 of 17 (100.0%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.009%) to 99.517%

Files with Coverage Reduction New Missed Lines %
lib/hexo/post.ts 1 99.64%
Totals Coverage Status
Change from base Build 13724198073: -0.009%
Covered Lines: 9887
Relevant Lines: 9935

💛 - Coveralls

@zombie12138 zombie12138 force-pushed the hotfix/swig-tag-conflict branch from 6134a97 to de619bb Compare March 22, 2025 08:52
@@ -254,6 +267,7 @@ class Tag {
const { env } = this;

if (env.hasExtension(name)) env.removeExtension(name);
delete this.block_swig_tag_map[name];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not this.block_swig_tag_map[name] = false?

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 this pull request may close these issues.

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