fix(schema): keep the extension when a filename has repeated dots (#1642)

This commit is contained in:
Hampus authored and GitHub committed 2026-08-15 20:06:19 +02:00
1 parent 5cd22ee84e
commit 3ed43ca00f
2 files changed
+10 -3

No files matched your search

@@ -59,7 +59,7 @@ export function normalizeFilename(value: string): string {
let normalized = normalizeString(value);
normalized = normalized.replaceAll(String.fromCharCode(0), '');
normalized = normalized.replace(/[/\\]/g, '_');
normalized = normalized.replace(/\.{2,}/g, '_');
normalized = normalized.replace(/\.{2,}/g, '.');
while (normalized.includes('..')) {
normalized = normalized.replace(/\.\./g, '_');
}
@@ -38,11 +38,18 @@ describe('FilenameType', () => {
expect(result.data).toBe('path_to_file.txt');
}
});
it('replaces double dots with underscores', () => {
it('collapses repeated dots into a single dot', () => {
const result = FilenameType.safeParse('..file..txt');
expect(result.success).toBe(true);
if (result.success) {
expect(result.data).not.toContain('..');
expect(result.data).toBe('.file.txt');
}
});
it('keeps the extension when the name contains repeated dots', () => {
const result = FilenameType.safeParse('video..mp4');
expect(result.success).toBe(true);
if (result.success) {
expect(result.data).toBe('video.mp4');
}
});
it('handles Windows reserved names by prefixing', () => {