Skip to content

Fix addLog: use regex with global flag and fix backtick no-op#4646

Open
ShehabSherif0 wants to merge 1 commit intomicrosoft:mainfrom
ShehabSherif0:fix/addLog-replace-missing-global-flag
Open

Fix addLog: use regex with global flag and fix backtick no-op#4646
ShehabSherif0 wants to merge 1 commit intomicrosoft:mainfrom
ShehabSherif0:fix/addLog-replace-missing-global-flag

Conversation

@ShehabSherif0
Copy link

Fixes #4645

The addLog methods in InlineEditRequestLogContext and DiagnosticInlineEditRequestLogContext use String.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:

# Bug Cause
1 Only first \n escaped String.prototype.replace with string arg has no global semantics
2 Only first \t escaped Same as above
3 Backtick escaping is a no-op '\' === '' in JavaScript (not a recognized escape sequence)

Before:

this._logs.push(content.replace('\n', '\\n').replace('\t', '\\t').replace('`', '\`') + '\n');

After:

this._logs.push(content.replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/`/g, '\\`') + '\n');

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.

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.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 addLog escaping from single-occurrence string replacements to global regex replacements for \n and \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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

addLog escaping only replaces first occurrence and backtick escape is a no-op

3 participants