fix(core): Preserve significant trailing spaces in gitignore patterns (#11536)

This commit is contained in:
Eric Rahm
2025-10-20 14:41:33 -07:00
committed by GitHub
parent 61a71c4fcd
commit d5a06d3cd2
2 changed files with 21 additions and 1 deletions

View File

@@ -250,4 +250,24 @@ src/*.tmp
expect(parser.isIgnored('bla/!bar')).toBe(true);
});
});
describe('Trailing Spaces', () => {
beforeEach(async () => {
await setupGitRepo();
});
it('should correctly handle significant trailing spaces', async () => {
await createTestFile('.gitignore', 'foo\\ \nbar ');
await createTestFile('foo ', 'content');
await createTestFile('bar', 'content');
await createTestFile('bar ', 'content');
// 'foo\ ' should match 'foo '
expect(parser.isIgnored('foo ')).toBe(true);
// 'bar ' should be trimmed to 'bar'
expect(parser.isIgnored('bar')).toBe(true);
expect(parser.isIgnored('bar ')).toBe(false);
});
});
});

View File

@@ -42,7 +42,7 @@ export class GitIgnoreParser implements GitIgnoreFilter {
return content
.split('\n')
.map((p) => p.trim())
.map((p) => p.trimStart())
.filter((p) => p !== '' && !p.startsWith('#'))
.map((p) => {
const isNegative = p.startsWith('!');