Sanitize filenames for notes resources

This commit is contained in:
Kovid Goyal 2023-09-16 13:11:51 +05:30
parent fa83be4192
commit 1fb3b9ea28
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -11,6 +11,7 @@ from contextlib import suppress
from itertools import count, repeat from itertools import count, repeat
from typing import Optional from typing import Optional
from calibre import sanitize_file_name
from calibre.constants import iswindows from calibre.constants import iswindows
from calibre.db import FTSQueryError from calibre.db import FTSQueryError
from calibre.db.annotations import unicode_normalize from calibre.db.annotations import unicode_normalize
@ -322,6 +323,7 @@ class Notes:
f = open(path, 'wb') f = open(path, 'wb')
with f: with f:
f.write(data) f.write(data)
name = sanitize_file_name(name)
base_name, ext = os.path.splitext(name) base_name, ext = os.path.splitext(name)
c = 0 c = 0
for (existing_name,) in conn.execute('SELECT name FROM notes_db.resources WHERE hash=?', (resource_hash,)): for (existing_name,) in conn.execute('SELECT name FROM notes_db.resources WHERE hash=?', (resource_hash,)):