Fix addLog: use regex with global flag and fix backtick no-op#4646
Open
ShehabSherif0 wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix addLog: use regex with global flag and fix backtick no-op#4646ShehabSherif0 wants to merge 1 commit intomicrosoft:mainfrom
ShehabSherif0 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
The addLog methods in InlineEditRequestLogContext and
DiagnosticInlineEditRequestLogContext have three bugs per line:
1. .replace('\n', ...) only replaces the first newline (missing /g)
2. .replace('\t', ...) only replaces the first tab (missing /g)
3. .replace('`', '\`') is a no-op because '\`' evaluates to '`'
in JavaScript (backslash-backtick is not a recognized escape
sequence, so the backslash is silently dropped)
Use regex literals with the global flag for all three replacements
so that every occurrence of newlines, tabs, and backticks is properly
escaped in the markdown log output.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes incorrect escaping behavior in inline edit diagnostic/debug log output by ensuring all occurrences of newline/tab/backtick characters are escaped and by correcting a JavaScript backtick “escape” that was previously a no-op. This improves the reliability of markdown log rendering in inline edit debug panels.
Changes:
- Switch
addLogescaping from single-occurrence string replacements to global regex replacements for\nand\t. - Fix backtick escaping to actually emit ``` (previously replaced backtick with backtick).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/platform/inlineEdits/common/inlineEditLogContext.ts | Fixes InlineEditRequestLogContext.addLog to escape all newlines/tabs/backticks correctly for markdown logs. |
| src/extension/inlineEdits/vscode-node/features/diagnosticsBasedCompletions/diagnosticsCompletions.ts | Applies the same escaping fix to DiagnosticInlineEditRequestLogContext.addLog for diagnostics logging output. |
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.
Fixes #4645
The
addLogmethods inInlineEditRequestLogContextandDiagnosticInlineEditRequestLogContextuseString.prototype.replace()with a string first argument. This only replaces the first occurrence.Additionally, the backtick replacement is a complete no-op: in JavaScript,
'\'is not a recognized escape sequence, so the backslash is silently dropped and the replacement string evaluates to just a plain backtick. The call.replace('', '\')` replaces backtick with backtick and does nothing.Three bugs per line, two affected files:
\nescapedString.prototype.replacewith string arg has no global semantics\tescaped'\' === ''in JavaScript (not a recognized escape sequence)Before:
After:
Both files contain identical buggy code from the initial commit. The fix uses regex literals with the global flag for all three replacements so that every occurrence is properly escaped in the markdown log output.