Python imports are mangled when source code html is rewritten
blackrobot opened this issue · comments
Describe the bug
In some cases on Python code, import
lines in the source code will be altered and rewritten to the page incorrectly, changing the text that appears to the user.
To Reproduce
Steps to reproduce the behavior:
- Go to https://github.com/django/django/blob/a9a7421ab83361746549d574ca13438ba93c95fe/django/contrib/auth/checks.py#L4
- See that the
from django.apps import apps
code on line is mangled and now appears asfrom django.appsapps import
Expected behavior
The line should appear with the source code unmodified.
Additional context
This is an example of what the source code looks like with OctoLinker disabled:
This is what the same source code looks like with OctoLinker enabled:
Here are the HTML snippets for the line with OctoLinker disabled and enabled:
<!-- OctoLinker Disabled -->
<tr>
<td id="L4" class="blob-num js-line-number" data-line-number="4"></td>
<td id="LC4" class="blob-code blob-code-inner js-file-line highlighted">
<span class="pl-k">from</span>
<span class="pl-s1">django</span>.
<span class="pl-s1">apps</span>
<span class="pl-k">import</span>
<span class="pl-s1">apps</span>
</td>
</tr>
<!-- OctoLinker Enabled -->
<tr>
<td id="L4" class="blob-num js-line-number" data-line-number="4"></td>
<td id="LC4" class="blob-code blob-code-inner js-file-line highlighted">
<span class="pl-k">from</span>
<a data-pjax="true" class="octolinker-link" href="https://www.djangoproject.com">
<span class="pl-s1">django</span>.
<span class="pl-s1">apps</span>
<span class="pl-s1">
<span class="pl-token" data-hydro-click="{"event_type":"code_navigation.click_on_symbol","payload":{"action":"click_on_symbol","repository_id":4164482,"ref":"a9a7421ab83361746549d574ca13438ba93c95fe","language":"Python","originating_url":"https://github.com/django/django/blob/a9a7421ab83361746549d574ca13438ba93c95fe/django/contrib/auth/checks.py","user_id":85895}}" data-hydro-click-hmac="a987f9b6fad47553f0ed81d9247442e2c673144f316ce4e8b99e506dae4ab0f5">apps</span>
</span>
</a>
<span class="pl-k">import</span>
</td>
</tr>
You can see a diff of the HTML snippets here: https://gist.github.com/blackrobot/f1510623f0bd6cbfbb18548a7a05f76b/revisions#diff-e02d99b9cd51b80ec76ae5342aca61845b5960b7715c79786fa9826544870155
Thanks for the very detailed explanation. This seems to be related to #1165, but unfortunately the fix does not solve this problem. However, it's realtead and therefore I'm optimistic to find a solution.
This has been fixed in version 6.8.1. Thanks again for filling the issue and sorry for the inconvenience.