Repository navigation
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Bad HTML filtering regexp High
Copilot Autofix
AI 6 months ago
In general, the robust way to fix this is to avoid hand-written HTML-stripping regexes entirely and instead rely on a well-tested HTML parser or sanitization library that understands browser quirks (for example, ignoring attributes on closing tags, handling malformed tags, etc.). For this specific case, we want to keep existing behavior and minimize changes, while making the "final safety step" actually remove any remaining script content that a browser might interpret as a script, even if the closing tag is malformed.
The single best minimal change here is to stop trying to match well-formed
<script>...</script>blocks with a regex that insists on a precise</script>end tag. Instead, we can: (1) remove any remaining<scriptstart tags in a loop, regardless of how they are closed, and (2) optionally also remove standalone</script-like closing tags. Since this function already strips all other tags, losing only the script tag text (or even the script contents) is acceptable and aligns with the comment that this is a "final safety step". Concretely, withinhtmlToMarkdownnear lines 1011–1018 indocs-engine/src/scraping/sphinxScraper.ts, replace the currentscriptTagPatternanddo/whileloop with a simpler pattern that matches any<scripttag (opening or malformed), such as/<\/?script\b[^>]*>/gi, and run it until no more matches remain. That avoids reliance on a specific</script>shape, and covers odd cases like</script foo="bar">. No additional imports or helper functions are required.