mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 14:25:23 +00:00
Fixes silent disappearance of Markdown (pseudo-)link when it's detected as unsafe protocol. Now it will be converted to plain text in spirit of [the specification](https://spec.commonmark.org/0.30/#links). For that sake the check for protocol is added to rst.nim also.
This commit is contained in:
@@ -843,12 +843,7 @@ suite "Warnings":
|
||||
rnInner
|
||||
rnLeaf 'foo'
|
||||
rnInner
|
||||
rnLeaf '#'
|
||||
rnLeaf 'foo'
|
||||
rnLeaf ','
|
||||
rnLeaf 'string'
|
||||
rnLeaf ','
|
||||
rnLeaf 'string'
|
||||
rnLeaf '#foo,string,string'
|
||||
rnParagraph anchor='foo'
|
||||
rnLeaf 'Paragraph'
|
||||
rnLeaf '.'
|
||||
@@ -1256,3 +1251,23 @@ suite "RST inline markup":
|
||||
rnLeaf 'my {link example'
|
||||
rnLeaf 'http://example.com/bracket_(symbol_[)'
|
||||
""")
|
||||
|
||||
test "not a Markdown link":
|
||||
# bug #17340 (27) `f` will be considered as a protocol and blocked as unsafe
|
||||
var warnings = new seq[string]
|
||||
check("[T](f: var Foo)".toAst(warnings = warnings) ==
|
||||
dedent"""
|
||||
rnInner
|
||||
rnLeaf '['
|
||||
rnLeaf 'T'
|
||||
rnLeaf ']'
|
||||
rnLeaf '('
|
||||
rnLeaf 'f'
|
||||
rnLeaf ':'
|
||||
rnLeaf ' '
|
||||
rnLeaf 'var'
|
||||
rnLeaf ' '
|
||||
rnLeaf 'Foo'
|
||||
rnLeaf ')'
|
||||
""")
|
||||
check(warnings[] == @["input(1, 5) Warning: broken link 'f'"])
|
||||
|
||||
@@ -1593,8 +1593,15 @@ suite "invalid targets":
|
||||
test "invalid links":
|
||||
check("(([Nim](https://nim-lang.org/)))".toHtml ==
|
||||
"""((<a class="reference external" href="https://nim-lang.org/">Nim</a>))""")
|
||||
check("(([Nim](javascript://nim-lang.org/)))".toHtml ==
|
||||
"""((<a class="reference external" href="">Nim</a>))""")
|
||||
# unknown protocol is treated just like plain text, not a link
|
||||
var warnings = new seq[string]
|
||||
check("(([Nim](javascript://nim-lang.org/)))".toHtml(warnings=warnings) ==
|
||||
"""(([Nim](javascript://nim-lang.org/)))""")
|
||||
check(warnings[] == @["input(1, 9) Warning: broken link 'javascript'"])
|
||||
warnings[].setLen 0
|
||||
check("`Nim <javascript://nim-lang.org/>`_".toHtml(warnings=warnings) ==
|
||||
"""Nim <javascript://nim-lang.org/>""")
|
||||
check(warnings[] == @["input(1, 33) Warning: broken link 'javascript'"])
|
||||
|
||||
suite "local file inclusion":
|
||||
test "cannot include files in sandboxed mode":
|
||||
|
||||
Reference in New Issue
Block a user