From: Günter M. <mi...@us...> - 2024-08-07 12:22:37
|
Unfortunately, I don't know what the "test failure on Windows" actually is, could you provide the relevant test output, please? > Is it possible to use the simpler unquote() here? If it works on Windows, using unquote() is a good idea. Could you test with ~~~ diff --git a/docutils/docutils/writers/_html_base.py b/docutils/docutils/writers/_html_base.py index ead930e31..2eab36510 100644 --- a/docutils/docutils/writers/_html_base.py +++ b/docutils/docutils/writers/_html_base.py @@ -626,7 +626,7 @@ def uri2imagepath(self, uri): uri_parts = urllib.parse.urlparse(uri) if uri_parts.scheme not in ('', 'file'): raise ValueError('Can only read local images.') - imagepath = urllib.request.url2pathname(uri_parts.path) + imagepath = urllib.parse.unquote(uri_parts.path) if imagepath.startswith('/'): # cf. config.html#root-prefix root_prefix = Path(self.settings.root_prefix) imagepath = (root_prefix/imagepath[1:]).as_posix() ~~~ and adapt the test script if required? > Perhaps we should use proper path handling if there is no URI scheme (i.e. the user has provided a file-path). Per definitionem, there is no way to provide a system file-path as image ressource, both [rST](https://docutils.sourceforge.io/docs/ref/rst/directives.html#image) and the [Docutils Doctree](https://docutils.sourceforge.io/docs/ref/doctree.html#image) explicitely expect an URI. As URIs are capable of representing local file paths, I dont see the advantage. Interpreting an image URI with undefined scheme as system path would be a complication of both, specification and implementation and a backwards-incompatible change. We would als have to think about images that are only read to get the size but kept external in HTML output. --- **[bugs:#493] Test failure on Windows with embedded images** **Status:** open **Created:** Wed Aug 07, 2024 02:25 AM UTC by Adam Turner **Last Updated:** Wed Aug 07, 2024 02:25 AM UTC **Owner:** nobody xref [r9785], [r9853], [r9855] Dear @milde, Thank you for the fix to my recent patch. It seems neither my patch nor the fix addressed the root cause of the test failures, as tests have resumed failing on Windows. I believe the following demonstrates the problem: ```pycon >>> import sys; print(sys.platform) win32 >>> import urllib.parse, urllib.request >>> urllib.request.url2pathname('test/data/circle-broken.svg') 'test\\data\\circle-broken.svg' >>> urllib.parse.unquote('test/data/circle-broken.svg') 'test/data/circle-broken.svg' ``` Currently, we use `imagepath = urllib.request.url2pathname(uri_parts.path)`, which converts path separators to their platform-native format. On UNIX, `url2pathname` simply calls `unquote`, but on Windows it handles UNC paths (``\\host\path\``) and escaped drive letters (``///C|/users/``). I don't know what led to using `url2pathname()`, as it is quite specialised (the docstring notes "not recommended for general use"). Is it possible to use the simpler `unquote()` here? For local file paths (e.g. without a ``file:///`` scheme), should we even be using URI parsing? Perhaps we should use proper path handling if there is no URI scheme (i.e. the user has provided a file-path). A --- Sent from sourceforge.net because doc...@li... is subscribed to https://sourceforge.net/p/docutils/bugs/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/docutils/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |