Repository navigation
fix: detect raw end tags and comments inside code blocks - #45
Conversation
Aaqibhafeezkhan
left a comment
There was a problem hiding this comment.
Self-review:
- Extended
code-escapedto detect unexpected HTML comments. - Added detection for malformed closing tags using parse5 parser errors and source offsets.
- Preserved the existing allowed syntax-highlight spans.
- Added regression fixtures for the reported edge cases.
- Updated validation documentation.
- Verify the generated validator bundle is updated.
- Run the build, type checks, and complete test suite.
bd94cb0 to
b876470
Compare
|
Hey @Aaqibhafeezkhan , Thank you for raising the PR. I will review and get back to you. |
d89862e to
4101b69
Compare
malav2110
left a comment
There was a problem hiding this comment.
Thanks for picking this up, @Aaqibhafeezkhan. A raw comment and a raw </div> in a code block now fail the check, and every sample still passes.
Two things block it. The workflow changes need to come out. And the </pre><script> case from #40 still passes in a bare <pre>, with no fixture that shows it. The rest are non-blocking.
I also need to correct my note on the issue: onParseError was the wrong pointer. My comment on src/validate-output.ts lines 278-301 explains why.
121835a to
018426b
Compare
malav2110
left a comment
There was a problem hiding this comment.
Thanks, @Aaqibhafeezkhan. This covers everything from my last review. The workflow is back to the original step, the bare <pre> case and the other three now fail, and every sample still passes.
A couple of small things remain before I merge:
- The PR description now describes a different change, a label check that closes #137. Could you put back a description of this change with "Closes #40", so the issue closes on merge?
- An off-by-one in the new comment range, inline below.
Once those are in, I don't need another round.
| for (const comment of filter(isComment, document.children, true)) { | ||
| const start = comment.startIndex ?? -1; | ||
| const end = comment.endIndex ?? start; | ||
| ignoredRanges.push({ start, end: end + 1 }); |
There was a problem hiding this comment.
suggestion (non-blocking): The new end-tag search skips an end tag written right after a comment.
The tree adapter already sets endIndex to parse5's endOffset, which points one character past the comment. Adding 1 pushes the range onto the < of the next tag, so <p>x</p><!-- note --></div> passes. Inside a code block the comment itself still fails the check, so this only hides an end tag outside one. No sample page has this pattern today.
A fail page with <!-- note --></div> would cover the fix. Separately, no test or sample page touches the comment and script exclusions yet. A pass page with <!-- </div> --> and a "</div>" string inside a <script> would cover them.
| ignoredRanges.push({ start, end: end + 1 }); | |
| ignoredRanges.push({ start, end }); |
Signed-off-by: Aaqibhafeez Khan <githubaaqibhafeezkhan@gmail.com>
b74f05c to
93b85db
Compare
malav2110
left a comment
There was a problem hiding this comment.
Thank you @Aaqibhafeezkhan . Merging in.
Summary
Detect raw HTML comments and unmatched closing tags inside code blocks, including bare
<pre>blocks.Changes
<pre>blocks.Closes #40