diff --git a/static/ui.js b/static/ui.js
index 7c9d0132..b21ffc3c 100644
--- a/static/ui.js
+++ b/static/ui.js
@@ -3757,10 +3757,20 @@ function renderMd(raw){
return false;
}
}
+ const SAFE_LABEL_INLINE=/^<\/?(strong|em|del|code)([\s>]|$)/i;
+ function _markdownLabelHtml(label){
+ const _label_stash=[];
+ const tokenized=String(label||'').replace(/<\/?[a-z][^>]*>/gi,tag=>{
+ if(!SAFE_LABEL_INLINE.test(tag)) return tag;
+ _label_stash.push(tag);
+ return `\x00H${_label_stash.length-1}\x00`;
+ });
+ return esc(tokenized).replace(/\x00H(\d+)\x00/g,(_,i)=>_label_stash[+i]);
+ }
function _markdownAnchor(label,rawUrl){
const href=_markdownHref(rawUrl);
const internal=/^session:\/\//i.test(String(rawUrl||'')) || _isInternalSessionHref(href);
- return `${esc(label)}`;
+ return `${_markdownLabelHtml(label)}`;
}
function _isSafeUrl(v, img){
const raw=_safeAttrValue(v);
diff --git a/tests/test_issue4001_inline_code_link_label.py b/tests/test_issue4001_inline_code_link_label.py
new file mode 100644
index 00000000..b14951e2
--- /dev/null
+++ b/tests/test_issue4001_inline_code_link_label.py
@@ -0,0 +1,22 @@
+from tests.test_renderer_js_behaviour import _render, driver_path # noqa: F401
+
+
+def test_inline_code_inside_link_label_renders_as_code(driver_path):
+ out = _render(driver_path, "[`8c64957`](https://github.com/x/y)")
+ assert '8c64957" in out
+ assert "<code>" not in out
+
+
+def test_list_item_link_label_keeps_inline_code(driver_path):
+ out = _render(driver_path, "- [`8c64957`](https://github.com/x/y)")
+ assert "" in out
+ assert "8c64957" in out
+ assert "<code>" not in out
+
+
+def test_unknown_raw_html_inside_link_label_is_escaped_once(driver_path):
+ out = _render(driver_path, "[](https://github.com/x/y)")
+ assert "