Merge pull request 'Fix markdown renderer under dashboard subpath' (#64) from timmy/63-resolve-markdown-renderer-under-dashboard-subpath into main
Merge pull request 'Fix markdown renderer under dashboard subpath' (#64)
This commit is contained in:
commit
5ca87c1b7c
|
|
@ -159,7 +159,7 @@ textarea { resize: vertical; min-height: 120px; }
|
|||
|
||||
<div class="footer">Creative AI-imbued UI • stackchain-dashboard</div>
|
||||
|
||||
<script src="/static/markdown.js"></script>
|
||||
<script src="static/markdown.js"></script>
|
||||
<script src="static/commands.js"></script>
|
||||
<script>
|
||||
(function(){
|
||||
|
|
|
|||
|
|
@ -1,9 +1,24 @@
|
|||
import json
|
||||
import subprocess
|
||||
from html.parser import HTMLParser
|
||||
from pathlib import Path
|
||||
from urllib.parse import urljoin
|
||||
|
||||
|
||||
RENDERER = Path(__file__).parent.parent / "frontend" / "markdown.js"
|
||||
FRONTEND = Path(__file__).parent.parent / "frontend"
|
||||
RENDERER = FRONTEND / "markdown.js"
|
||||
|
||||
|
||||
class ScriptSourceParser(HTMLParser):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.sources = []
|
||||
|
||||
def handle_starttag(self, tag, attrs):
|
||||
if tag == "script":
|
||||
source = dict(attrs).get("src")
|
||||
if source:
|
||||
self.sources.append(source)
|
||||
|
||||
|
||||
def test_markdown_renderer_escapes_raw_html_before_rendering_heading():
|
||||
|
|
@ -23,3 +38,15 @@ def test_markdown_renderer_escapes_raw_html_before_rendering_heading():
|
|||
assert result.stdout == (
|
||||
"<h1><img src=x onerror=alert(document.domain)></h1>"
|
||||
)
|
||||
|
||||
|
||||
def test_markdown_script_resolves_inside_dashboard_subpath():
|
||||
parser = ScriptSourceParser()
|
||||
parser.feed((FRONTEND / "index.html").read_text())
|
||||
markdown_source = next(
|
||||
source for source in parser.sources if source.endswith("markdown.js")
|
||||
)
|
||||
|
||||
assert urljoin(
|
||||
"https://forge.alexanderwhitestone.com/dashboard/", markdown_source
|
||||
) == "https://forge.alexanderwhitestone.com/dashboard/static/markdown.js"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user