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
|
import shutil
|
||||||
from html5_parser import parse
|
from html5_parser import parse
|
||||||
from lxml import html
|
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.ebooks.chardet import xml_to_unicode
|
||||||
from calibre.utils.cleantext import clean_xml_chars
|
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:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
if purl.scheme in ('', 'file'):
|
if purl.scheme in ('', 'file'):
|
||||||
path = purl.path
|
path = unquote(purl.path)
|
||||||
if not os.path.isabs(path):
|
if not os.path.isabs(path):
|
||||||
path = os.path.join(basedir, path)
|
path = os.path.join(basedir, path)
|
||||||
q = os.path.normcase(get_long_path_name(os.path.abspath(path)))
|
q = os.path.normcase(get_long_path_name(os.path.abspath(path)))
|
||||||
|
@ -124,7 +124,7 @@ def test_cache_api(self: 'NotesTest'):
|
|||||||
self.assertIsNone(cache.get_notes_resource(h1))
|
self.assertIsNone(cache.get_notes_resource(h1))
|
||||||
self.assertIsNone(cache.get_notes_resource(h2))
|
self.assertIsNone(cache.get_notes_resource(h2))
|
||||||
# test exim of note
|
# 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:
|
with tempfile.TemporaryDirectory() as tdir:
|
||||||
idir = os.path.join(tdir, 'i')
|
idir = os.path.join(tdir, 'i')
|
||||||
os.mkdir(idir)
|
os.mkdir(idir)
|
||||||
@ -139,7 +139,7 @@ def test_cache_api(self: 'NotesTest'):
|
|||||||
os.mkdir(edir)
|
os.mkdir(edir)
|
||||||
index_name = cache.export_note('authors', author_id, edir)
|
index_name = cache.export_note('authors', author_id, edir)
|
||||||
with open(os.path.join(edir, index_name)) as f:
|
with open(os.path.join(edir, index_name)) as f:
|
||||||
self.assertIn(doc, f.read())
|
self.assertIn(doc.replace('r 1.png', 'r%201.png'), f.read())
|
||||||
for x in ('r 1.png', 'r 2.png'):
|
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:
|
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())
|
self.assertEqual(a.read(), b.read())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user