Repository: microsoft/vscode (TypeScript)
Date: 2023-08-22 12:54:11+00:00
Task type: Bug Fix

Issue:
Unicode codepoint 0x202E causes the default filename in the tab title to also be right to left
<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.81.0
- OS Version: Windows 11 Pro - Version	10.0.22621 Build 22621

Steps to Reproduce:

1. Create a new text file
2. Paste the following text into the editor (Note the text is preceded by unicode codepoint 0x202E): ‮Right to left test
Tab title displays as ‮Right to left testUntitled-1
![image](https://github.com/microsoft/vscode/assets/107897376/716fd348-a909-45d5-ba70-ec29b61833a9)

4. Delete unicode codepoint 0x202E
Tab title displays as: Right to left test 1-deltitnU
![image](https://github.com/microsoft/vscode/assets/107897376/bd315fa2-d306-4e28-9646-d026f4eaa702)




Issue discussion:
Good finding, we do some text normalization (removing spaces) here:

https://github.com/microsoft/vscode/blob/652e2d069c57887ec97f3ebac29533e44919cf14/src/vs/workbench/services/untitled/common/untitledTextEditorModel.ts#L415-L426

But we should probably strip out all non-printable unicode sequences.

If someone has an idea how to address this, opening for help wanted.
Hi, I'd like to try and take this one. I thought I had a fix, however it didn't quite pass the test script so i'll have to take another look at it later today.
Hey @bpasero, quick question for you. I've been messing with the code a bit and I've found a solution that seemingly solves the issue, however I cant get it to pass this certain test even tho the expected and the actual are the same? Is there something wrong with the test or is there something that I am not noticing?
```
8960 passing (45s)
  54 pending
  1 failing

  1) Untitled text editors
       model#onDidChangeName and input name:

      
      + expected - actual

      -123456789012345678901234567890123456789 
      +123456789012345678901234567890123456789
      
  fakestack

```
  
  Additionally, aside from this issue when I cloned my vscode fork to my new mac and installed all the dependancies, I am noticing that the Ext - Build never completes and throws a bunch of errors prior to me even doing anything with the project. Is this something widespread or have I possibly installed something wrong. Thanks!



Solution patch:
diff --git a/src/vs/workbench/services/untitled/common/untitledTextEditorModel.ts b/src/vs/workbench/services/untitled/common/untitledTextEditorModel.ts
--- a/src/vs/workbench/services/untitled/common/untitledTextEditorModel.ts
+++ b/src/vs/workbench/services/untitled/common/untitledTextEditorModel.ts
@@ -419,7 +419,8 @@ export class UntitledTextEditorModel extends BaseTextEditorModel implements IUnt
 				startColumn: 1,
 				endColumn: UntitledTextEditorModel.FIRST_LINE_NAME_CANDIDATE_MAX_LENGTH + 1		// first cap at FIRST_LINE_NAME_CANDIDATE_MAX_LENGTH
 			})
-			.trim().replace(/\s+/g, ' '); 														// normalize whitespaces
+			.trim().replace(/\s+/g, ' ') 														// normalize whitespaces
+			.replace(/\u202E/g, '');															// drop Right-to-Left Override character (#190133)
 		firstLineText = firstLineText.substr(0, getCharContainingOffset(						// finally cap at FIRST_LINE_NAME_MAX_LENGTH (grapheme aware #111235)
 			firstLineText,
 			UntitledTextEditorModel.FIRST_LINE_NAME_MAX_LENGTH)[0]


Test patch:
diff --git a/src/vs/workbench/services/untitled/test/browser/untitledTextEditor.test.ts b/src/vs/workbench/services/untitled/test/browser/untitledTextEditor.test.ts
--- a/src/vs/workbench/services/untitled/test/browser/untitledTextEditor.test.ts
+++ b/src/vs/workbench/services/untitled/test/browser/untitledTextEditor.test.ts
@@ -542,11 +542,15 @@ suite('Untitled text editors', () => {
 		assert.strictEqual(input.getName(), '123456789012345678901234567890123456789');
 		assert.strictEqual(model.name, '123456789012345678901234567890123456789');
 
-		assert.strictEqual(counter, 6);
+		model.textEditorModel?.setValue('hello\u202Eworld'); // do not allow RTL in names (#190133)
+		assert.strictEqual(input.getName(), 'helloworld');
+		assert.strictEqual(model.name, 'helloworld');
 
-		model.textEditorModel?.setValue('Hello\nWorld');
 		assert.strictEqual(counter, 7);
 
+		model.textEditorModel?.setValue('Hello\nWorld');
+		assert.strictEqual(counter, 8);
+
 		function createSingleEditOp(text: string, positionLineNumber: number, positionColumn: number, selectionLineNumber: number = positionLineNumber, selectionColumn: number = positionColumn): ISingleEditOperation {
 			const range = new Range(
 				selectionLineNumber,
@@ -563,7 +567,7 @@ suite('Untitled text editors', () => {
 		}
 
 		model.textEditorModel?.applyEdits([createSingleEditOp('hello', 2, 2)]);
-		assert.strictEqual(counter, 7); // change was not on first line
+		assert.strictEqual(counter, 8); // change was not on first line
 
 		input.dispose();
 		model.dispose();