mirror of
https://github.com/microsoft/vscode.git
synced 2026-06-06 07:35:52 +01:00
tools: always replace explicit tab in apply_patch insertions (#223)
Closes https://github.com/microsoft/vscode/issues/254783
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user