Skip to content

Fix missing global flag in sanitizeId regex#303603

Merged
rzhao271 merged 2 commits intomicrosoft:mainfrom
ShehabSherif0:fix/sanitize-id-missing-global-flag
Mar 20, 2026
Merged

Fix missing global flag in sanitizeId regex#303603
rzhao271 merged 2 commits intomicrosoft:mainfrom
ShehabSherif0:fix/sanitize-id-missing-global-flag

Conversation

@ShehabSherif0
Copy link
Contributor

Fixes #303601

The sanitizeId regex was missing the g (global) flag, so String.prototype.replace only replaced the first occurrence of . or /. Since settings IDs contain multiple dots (e.g., editor.font.size), only the first one was being sanitized to _.

Before: "root.editor.font.size" -> "root_editor.font.size"
After: "root.editor.font.size" -> "root_editor_font_size"

The regex in sanitizeId was missing the 'g' flag, so only the first
occurrence of '.' or '/' was replaced with '_'. Since settings IDs
contain multiple dots (e.g. 'editor.font.size'), this meant subsequent
dots were left in the sanitized ID.
Copilot AI review requested due to automatic review settings March 20, 2026 19:58
@vs-code-engineering
Copy link
Contributor

vs-code-engineering bot commented Mar 20, 2026

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@rzhao271

Matched files:

  • src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts
  • src/vs/workbench/contrib/preferences/test/browser/settingsTreeModels.test.ts

@vs-code-engineering vs-code-engineering bot added this to the 1.113.0 milestone Mar 20, 2026
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 a sanitization bug in the Settings UI tree model where generated element IDs were only partially sanitized, causing IDs derived from setting keys with multiple separators (e.g. editor.font.size) to retain dots/slashes after the first replacement.

Changes:

  • Update sanitizeId to use a global regex so all . and / characters are replaced with _ during ID generation.

Export sanitizeId and add a test verifying that all occurrences of '.'
and '/' are replaced in generated tree element IDs, not just the first.
@rzhao271 rzhao271 enabled auto-merge (squash) March 20, 2026 21:12
@rzhao271 rzhao271 merged commit 5ce6509 into microsoft:main Mar 20, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sanitizeId regex missing global flag - only first dot/slash is replaced in settings tree IDs

4 participants