Skip to content

Commit d67fcc7

Browse files
committed
fix(web): normalize interior dot path segments
1 parent 321a14c commit d67fcc7

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎packages/web/src/lib/gitattributes.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('resolveLanguageFromGitAttributes', () => {
2121

2222
expect(resolveLanguageFromGitAttributes('docs/intro.txt', attrs)).toBe('Markdown');
2323
expect(resolveLanguageFromGitAttributes('./docs/intro.txt', attrs)).toBe('Markdown');
24+
expect(resolveLanguageFromGitAttributes('./docs/./intro.txt', attrs)).toBe('Markdown');
2425
expect(resolveLanguageFromGitAttributes('other/docs/intro.txt', attrs)).toBeUndefined();
2526
});
2627

‎packages/web/src/lib/gitattributes.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ export function parseGitAttributes(content: string): GitAttributes {
6363
// is matched against the full path from the repository root.
6464
// @see https://git-scm.com/docs/gitattributes#_description
6565
function matchesGitAttributesPattern(filePath: string, pattern: string): boolean {
66-
const normalizedFilePath = filePath.replace(/^(?:\.\/)+/, '');
66+
const normalizedFilePath = filePath
67+
.split('/')
68+
.filter((pathSegment) => pathSegment !== '.')
69+
.join('/');
6770
if (!pattern.includes('/')) {
6871
const fileName = normalizedFilePath.slice(normalizedFilePath.lastIndexOf('/') + 1);
6972
return micromatch.isMatch(fileName, pattern, { dot: true });

0 commit comments

Comments
 (0)