Strip markdown comments from stringified commits#528
Merged
Conversation
| } | ||
|
|
||
| function stripMarkdownComments(str: string): string { | ||
| return str.replace(/<!--[\s\S]*?-->/g, ''); |
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 year ago
To fix the problem, we need to ensure that all instances of the targeted pattern are removed, even if they appear consecutively or are nested. One effective way to achieve this is to apply the regular expression replacement repeatedly until no more replacements can be performed. This ensures that the unsafe text does not reappear in the sanitized input.
We will modify the stripMarkdownComments function to repeatedly apply the regular expression replacement until the input string no longer changes. This will ensure that all HTML comments are fully removed.
Suggested changeset
1
src/lib/github/v3/getPullRequest/getPullRequestBody.ts
| @@ -85,3 +85,8 @@ | ||
| function stripMarkdownComments(str: string): string { | ||
| return str.replace(/<!--[\s\S]*?-->/g, ''); | ||
| let previous; | ||
| do { | ||
| previous = str; | ||
| str = str.replace(/<!--[\s\S]*?-->/g, ''); | ||
| } while (str !== previous); | ||
| return str; | ||
| } |
Copilot is powered by AI and may make mistakes. Always verify output.
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow up to #526
This strips markdown comments like
<!-- markdown-comment -->in the stringified commit message{{commitsStringified}}