-
-
Notifications
You must be signed in to change notification settings - Fork 5k
fix: Incorrectly ignores single-line code blocks when escaping Swig and HTML comments #5722
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
base: master
Are you sure you want to change the base?
Conversation
How to testgit clone -b fix/swig https://github.com/D-Sketon/hexo.git
cd hexo
npm install
npm test |
Pull Request Test Coverage Report for Build 19190628262Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive support for handling inline code blocks (backticks) in the Hexo post rendering system. The changes prevent Swig tags, comments, and other special syntax within inline code blocks from being processed, ensuring they are properly escaped and displayed as literal text instead.
- Adds inline code block detection and handling logic to the post rendering escape system
- Extends test coverage for inline code blocks with various edge cases including swig tags, comments, and different backtick counts
- Fixes an existing test expectation to match actual HTML entity encoding behavior
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/hexo/post.ts | Adds STATE_INLINE_CODE state and associated logic to detect and escape inline code blocks, removes unused rCommentEscape regex and escapeComments method |
| test/scripts/hexo/post.ts | Adds Bluebird import and stub import, fixes test expectation for quotes encoding, adds extensive test coverage for inline code blocks including edge cases with swig tags, comments, and newlines |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: D-Sketon <2055272094@qq.com>
|
I commented on the issue reproduction conditions. See #5721 (comment) |
yoshinorin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is a bit complex, but it appears to be working as intended. I have one question though.
| if ((char === '\n' && next_char === '\n') | ||
| || (char === '\r' && next_char === '\n' && str[idx + 2] === '\r' && str[idx + 3] === '\n') | ||
| || (char === '\r' && next_char === '\n' && str[idx + 2] === '\n') | ||
| || (char === '\n' && next_char === '\r' && str[idx + 2] === '\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question:
Could you explain the reason for including the \r\n\n and \n\r\n patterns? Is it because line endings might be mixed between Linux/Mac and Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be considered a form of defensive programming. I'm not sure if scenarios with mixed \n and \r\n would actually occur in practice.
yoshinorin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
close #5721
Main Changes:
Introduced the STATE_INLINE_CODE state. In this state, apart from raw Swig tags being escaped, all other text (including HTML comments and Swig tags) will not be processed.
Impact:
{# #}within inline code blocks will no longer be skipped during rendering (I am uncertain whether this change is reasonable or if the previous behavior was a bug).Pull request tasks