diff --git a/lib/packages/docutils/rstgen.nim b/lib/packages/docutils/rstgen.nim index 2e45bda4ce..e2f0594613 100644 --- a/lib/packages/docutils/rstgen.nim +++ b/lib/packages/docutils/rstgen.nim @@ -40,7 +40,7 @@ ## can be done by simply searching for [footnoteName]. import strutils, os, hashes, strtabs, rstast, rst, highlite, tables, sequtils, - algorithm, parseutils, std/strbasics + algorithm, parseutils, std/strbasics, strscans import ../../std/private/since @@ -823,6 +823,16 @@ proc renderOverline(d: PDoc, n: PRstNode, result: var string) = rstnodeToRefname(n).idS, tmp, $chr(n.level - 1 + ord('A')), tocName]) +proc safeProtocol(linkStr: var string) = + var protocol = "" + if scanf(linkStr, "$w:", protocol): + # if it has a protocol at all, ensure that it's not 'javascript:' or worse: + if cmpIgnoreCase(protocol, "http") == 0 or cmpIgnoreCase(protocol, "https") == 0 or + cmpIgnoreCase(protocol, "ftp") == 0: + discard "it's fine" + else: + linkStr = "" + proc renderTocEntry(d: PDoc, e: TocEntry, result: var string) = dispA(d.target, result, "
"""
+
+ let input2 = dedent """.. image:: /images/myimage.jpg
+ :target: javascript://bar.com
+ :alt: Alt text for the image"""
+ let output2 = input2.toHtml
+ check output2 == """
"""
+
+ let input3 = dedent """.. image:: /images/myimage.jpg
+ :target: bar.com
+ :alt: Alt text for the image"""
+ let output3 = input3.toHtml
+ check output3 == """
"""
+
+ test "invalid links":
+ check("(([Nim](https://nim-lang.org/)))".toHtml ==
+ """((Nim))""")
+ check("(([Nim](javascript://nim-lang.org/)))".toHtml ==
+ """((Nim))""")