Unicode codepoint 0x202E causes the default filename in the tab title to also be right to left (fix #190133) (#190980)

This commit is contained in:
Benjamin Pasero 2023-08-22 15:27:52 +02:00 committed by GitHub
parent 90dfc646f4
commit 515c6b204f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -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]

View file

@ -542,10 +542,14 @@ 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');
assert.strictEqual(counter, 7);
model.textEditorModel?.setValue('Hello\nWorld');
assert.strictEqual(counter, 7);
assert.strictEqual(counter, 8);
function createSingleEditOp(text: string, positionLineNumber: number, positionColumn: number, selectionLineNumber: number = positionLineNumber, selectionColumn: number = positionColumn): ISingleEditOperation {
const range = new Range(
@ -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();