Replace spaces with underscores in uploaded files

This commit is contained in:
Alex Gleason committed 2025-09-20 19:05:53 -05:00
1 parent 75d4d13737
commit a3c204f44f
2 files changed
+41 -1

No files matched your search

+38
View File
@@ -153,5 +153,43 @@ describe('fileUtils', () => {
const savedContent = await mockFS.readFile('/tmp/test_1.txt', 'utf8');
expect(savedContent).toBe(fileContent);
});
it('should convert spaces to underscores in filename', async () => {
const fileContent = 'Hello, world!';
const arrayBuffer = new TextEncoder().encode(fileContent).buffer;
// Create a mock File object with spaces in the name
const file = {
name: 'my file with spaces.txt',
arrayBuffer: async () => arrayBuffer
} as File;
const savedPath = await saveFileToTmp(mockFS, file);
expect(savedPath).toBe('/tmp/my_file_with_spaces.txt');
// Verify file was actually saved with sanitized name
const savedContent = await mockFS.readFile('/tmp/my_file_with_spaces.txt', 'utf8');
expect(savedContent).toBe(fileContent);
});
it('should convert multiple consecutive spaces to single underscore', async () => {
const fileContent = 'test content';
const arrayBuffer = new TextEncoder().encode(fileContent).buffer;
// Create a mock File object with multiple spaces
const file = {
name: 'file with multiple spaces.txt',
arrayBuffer: async () => arrayBuffer
} as File;
const savedPath = await saveFileToTmp(mockFS, file);
expect(savedPath).toBe('/tmp/file_with_multiple_spaces.txt');
// Verify file was actually saved
const savedContent = await mockFS.readFile('/tmp/file_with_multiple_spaces.txt', 'utf8');
expect(savedContent).toBe(fileContent);
});
});
});