mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Handle URL quoting when importing notes
This commit is contained in:
parent
2076fa282d
commit
7df0ec7bee
@ -5,7 +5,7 @@ import os
|
||||
import shutil
|
||||
from html5_parser import parse
|
||||
from lxml import html
|
||||
from urllib.parse import urlparse
|
||||
from urllib.parse import unquote, urlparse
|
||||
|
||||
from calibre.ebooks.chardet import xml_to_unicode
|
||||
from calibre.utils.cleantext import clean_xml_chars
|
||||
@ -63,7 +63,7 @@ def import_note(path_to_html_file: str, add_resource) -> dict:
|
||||
except Exception:
|
||||
continue
|
||||
if purl.scheme in ('', 'file'):
|
||||
path = purl.path
|
||||
path = unquote(purl.path)
|
||||
if not os.path.isabs(path):
|
||||
path = os.path.join(basedir, path)
|
||||
q = os.path.normcase(get_long_path_name(os.path.abspath(path)))
|
||||
|
@ -124,14 +124,14 @@ def test_cache_api(self: 'NotesTest'):
|
||||
self.assertIsNone(cache.get_notes_resource(h1))
|
||||
self.assertIsNone(cache.get_notes_resource(h2))
|
||||
# test exim of note
|
||||
doc = '<p>test simple exim <img src="r1.png"> of note with resources <img src="r2.png">. Works or not</p>'
|
||||
doc = '<p>test simple exim <img src="r 1.png"> of note with resources <img src="r%202.png">. Works or not</p>'
|
||||
with tempfile.TemporaryDirectory() as tdir:
|
||||
idir = os.path.join(tdir, 'i')
|
||||
os.mkdir(idir)
|
||||
with open(os.path.join(idir, 'index.html'), 'w') as f:
|
||||
f.write(doc)
|
||||
shutil.copyfile(get_image_path('lt.png'), os.path.join(idir, 'r1.png'))
|
||||
shutil.copyfile(get_image_path('library.png'), os.path.join(idir, 'r2.png'))
|
||||
shutil.copyfile(get_image_path('lt.png'), os.path.join(idir, 'r 1.png'))
|
||||
shutil.copyfile(get_image_path('library.png'), os.path.join(idir, 'r 2.png'))
|
||||
note_id = cache.import_note('authors', author_id, f.name)
|
||||
self.assertGreater(note_id, 0)
|
||||
self.assertIn('<p>test simple exim <img', cache.notes_for('authors', author_id))
|
||||
@ -139,8 +139,8 @@ def test_cache_api(self: 'NotesTest'):
|
||||
os.mkdir(edir)
|
||||
index_name = cache.export_note('authors', author_id, edir)
|
||||
with open(os.path.join(edir, index_name)) as f:
|
||||
self.assertIn(doc, f.read())
|
||||
for x in ('r1.png', 'r2.png'):
|
||||
self.assertIn(doc.replace('r 1.png', 'r%201.png'), f.read())
|
||||
for x in ('r 1.png', 'r 2.png'):
|
||||
with open(os.path.join(idir, x), 'rb') as a, open(os.path.join(edir, x), 'rb') as b:
|
||||
self.assertEqual(a.read(), b.read())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user