tools: always replace explicit tab in apply_patch insertions (#223)

Closes https://github.com/microsoft/vscode/issues/254783
This commit is contained in:
Connor Peet
2025-07-11 14:27:55 -07:00
committed by GitHub
parent 8d6202052c
commit 27f90f9661
2 changed files with 37 additions and 7 deletions
@@ -408,19 +408,17 @@ export class Parser {
for (const ch of nextSection.chunks) {
ch.origIndex += match.line;
ch.insLines = ch.insLines.map(replace_explicit_tabs);
if (this.fixIndentationDuringMatch) {
ch.insLines = ch.insLines.map(ins => isFalsyOrWhitespace(ins) ? ins : additionalIndentation + transformIndentation(ins, srcIndentStyle, targetIndentStyle));
}
if (match.fuzz & Fuzz.NormalizedExplicitTab) {
action.chunks.push({
delLines: ch.delLines.map(replace_explicit_tabs),
insLines: ch.insLines.map(replace_explicit_tabs),
origIndex: ch.origIndex,
});
} else {
action.chunks.push(ch);
ch.delLines = ch.delLines.map(replace_explicit_tabs);
}
action.chunks.push(ch);
}
index = match.line + nextSection.nextChunkContext.length;
this.index = nextSection.endPatchIndex;
@@ -286,6 +286,38 @@ suite('applyPatch parser', () => {
]);
});
it('always normalizes explicit \\t tab chars in replacement', () => {
// 4.1 likes to explicitly put tabs as `\\t` in its patches
const input = `*** Begin Patch\n*** Update File: a.txt\n@@\n-hello\n+\\t\\tworld\n*** End Patch`;
expect(text_to_patch(input, {
'a.txt': new StringTextDocumentWithLanguageId('hello', 'text/plain')
})).toMatchInlineSnapshot(`
[
{
"actions": {
"a.txt": {
"chunks": [
{
"delLines": [
"hello",
],
"insLines": [
" world",
],
"origIndex": 0,
},
],
"movePath": undefined,
"type": "update",
},
},
},
0,
]
`);
});
suite('corpus', () => {
const corpusPath = path.join(__dirname, 'corpus');