Skip to content

Sequential relative URLs with colons in the text not rendering correctly using the render_markdown templatetag #8944

@drygdryg

Description

@drygdryg

NetBox version

v3.1.9

Python version

3.10

Steps to Reproduce

  1. Run NetBox shell and import the render_markdown templatetag:
$ /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py nbshell
### NetBox interactive shell (ubuntuserver)
### Python 3.10.2+ | Django 3.2.12 | NetBox 3.1.9
### lsmodels() will show available models. Use help(<model>) for more info.
>>> from utilities.templatetags.helpers import render_markdown
  1. Try to render test case URLs:
>>> render_markdown('[TEST](/dcim/devices/1/)')
'<div class="rendered-markdown"><p><a href="/dcim/devices/1/">TEST</a></p></div>'  # Correct
>>> render_markdown('[TEST:](/dcim/devices/1/)')
'<div class="rendered-markdown"><p><a href="/dcim/devices/1/">TEST:</a></p></div>'  # Correct
>>> render_markdown('[TEST](/dcim/devices/1/) [TEST](/dcim/devices/1/)')
'<div class="rendered-markdown"><p><a href="/dcim/devices/1/">TEST</a> <a href="/dcim/devices/1/">TEST</a></p></div>'  # Correct
>>> render_markdown('[TEST](/dcim/devices/1/) [TEST:](/dcim/devices/1/)')
'<div class="rendered-markdown"><p>[TEST](](/dcim/devices/1/)</p></div>'  # Incorrect
>>> render_markdown('[TEST](https://netbox.site/dcim/devices/1/) [TEST:](https://netbox.site/dcim/devices/1/)')
'<div class="rendered-markdown"><p><a href="https://netbox.site/dcim/devices/1/">TEST</a> <a href="https://netbox.site/dcim/devices/1/">TEST:</a></p></div>'  # Correct

Expected Behavior

The string

[TEST](/dcim/devices/1/) [TEST:](/dcim/devices/1/)

should be rendered as

<div class="rendered-markdown"><p><a href="/dcim/devices/1/">TEST</a> <a href="/dcim/devices/1/">TEST:</a></p></div>

Observed Behavior

The string

[TEST](/dcim/devices/1/) [TEST:](/dcim/devices/1/)

was rendered as

<div class="rendered-markdown"><p>[TEST](](/dcim/devices/1/)</p></div>

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions