OctoLinker / OctoLinker

OctoLinker — Links together, what belongs together

Home Page:https://octolinker.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

  1. Go to https://github.com/django/django/blob/a9a7421ab83361746549d574ca13438ba93c95fe/django/contrib/auth/checks.py#L4
  2. See that the from django.apps import apps code on line is mangled and now appears as from 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:

Correct code with OctoLinker disabled

This is what the same source code looks like with OctoLinker enabled:

Incorrect code 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="{&quot;event_type&quot;:&quot;code_navigation.click_on_symbol&quot;,&quot;payload&quot;:{&quot;action&quot;:&quot;click_on_symbol&quot;,&quot;repository_id&quot;:4164482,&quot;ref&quot;:&quot;a9a7421ab83361746549d574ca13438ba93c95fe&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;originating_url&quot;:&quot;https://github.com/django/django/blob/a9a7421ab83361746549d574ca13438ba93c95fe/django/contrib/auth/checks.py&quot;,&quot;user_id&quot;: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.