From c8c761b017e9aaf97dcf36b6f2114fe8c96aa288 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Thu, 29 Jan 2026 15:13:02 +0100 Subject: [PATCH] fix(sync): escape unsafe character in filename (#3109) --- apps/readest-app/src/__tests__/utils/misc.test.ts | 2 +- apps/readest-app/src/utils/misc.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/readest-app/src/__tests__/utils/misc.test.ts b/apps/readest-app/src/__tests__/utils/misc.test.ts index d2f16124..f6e92c15 100644 --- a/apps/readest-app/src/__tests__/utils/misc.test.ts +++ b/apps/readest-app/src/__tests__/utils/misc.test.ts @@ -193,7 +193,7 @@ describe('makeSafeFilename', () => { }); it('should handle string with only unsafe characters', () => { - expect(makeSafeFilename('<>:"|?*')).toBe('_______'); + expect(makeSafeFilename('<>:"|?*#')).toBe('________'); }); it('should handle string that becomes empty after sanitization and trimming', () => { diff --git a/apps/readest-app/src/utils/misc.ts b/apps/readest-app/src/utils/misc.ts index c4de55d6..3f44772e 100644 --- a/apps/readest-app/src/utils/misc.ts +++ b/apps/readest-app/src/utils/misc.ts @@ -9,7 +9,7 @@ export const getContentMd5 = (content: unknown) => md5(JSON.stringify(content)); export const makeSafeFilename = (filename: string, replacement = '_') => { // Windows restricted characters + control characters and reserved names - const unsafeCharacters = /[<>:%"\/\\|?*\x00-\x1F]/g; + const unsafeCharacters = /[<>:%#"\/\\|?*\x00-\x1F]/g; const reservedFilenames = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i; // Unsafe to use filename including file extensions over 255 bytes on Android const maxFilenameBytes = 250;