From: Günter M. <mi...@us...> - 2024-08-09 08:45:22
|
The parsing is correct: The image argument is a "URI reference": > A URI-reference is either a URI or a relative reference. If the URI-reference's prefix does not match the syntax of a scheme followed by its colon separator, then the URI-reference is a relative reference. (RFC 3986) Hence, the example ~~~ .. image:: S:/Development/data/circle-broken.svg ~~~ describes an image accessible under scheme "S". Our problem is, that we cannot easily use relative paths (to keep flexibility regarding where to run the tests from). A simple solution would be using a "file" scheme in the offending examples: ~~~ diff --git a/docutils/test/test_writers/test_html5_polyglot_parts.py b/docutils/test/test_writers/test_html5_polyglot_parts.py index ba139d65c..102273234 100755 --- a/docutils/test/test_writers/test_html5_polyglot_parts.py +++ b/docutils/test/test_writers/test_html5_polyglot_parts.py @@ -714,7 +714,7 @@ def format_output(self, parts): """, }], [f"""\ -.. image:: {DATA_ROOT}/circle-broken.svg +.. image:: file://{DATA_ROOT}/circle-broken.svg :loading: embed """, {'fragment': f"""\ @@ -725,7 +725,7 @@ def format_output(self, parts): <aside class="system-message"> <p class="system-message-title">System Message: ERROR/3 (<span class="docutils literal"><string></span>, line 1)</p> -<p>Cannot parse SVG image "{DATA_ROOT}/circle-broken.svg": +<p>Cannot parse SVG image "file://{DATA_ROOT}/circle-broken.svg": not well-formed (invalid token): line 3, column 48</p> </aside> """ @@ -831,7 +831,7 @@ def format_output(self, parts): """, }], [f"""\ -.. image:: {DATA_ROOT}/circle-broken.svg +.. image:: file://{DATA_ROOT}/circle-broken.svg :loading: embed """, {'fragment': """\ ~~~ --- **[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:** Thu Aug 08, 2024 08:43 PM 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. |