From c759d7abd1b4181fb4931bc95148beac3051bf91 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 18 Sep 2024 23:35:46 +0800 Subject: [PATCH] fixes rst parsing Markdown CodeblockFields blocking the loop (#24128) ```nim import packages/docutils/[rst, rstgen] let message = """```llvm-profdata""" echo rstgen.rstToHtml(message, {roSupportMarkdown}, nil) ``` --- lib/packages/docutils/rst.nim | 2 +- tests/stdlib/trst.nim | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/packages/docutils/rst.nim b/lib/packages/docutils/rst.nim index a51ee49a64..706c506893 100644 --- a/lib/packages/docutils/rst.nim +++ b/lib/packages/docutils/rst.nim @@ -1526,7 +1526,7 @@ proc parseMarkdownCodeblockFields(p: var RstParser): PRstNode = result = nil else: result = newRstNode(rnFieldList) - while currentTok(p).kind != tkIndent: + while currentTok(p).kind notin {tkIndent, tkEof}: if currentTok(p).kind == tkWhite: inc p.idx else: diff --git a/tests/stdlib/trst.nim b/tests/stdlib/trst.nim index 2a7f0d3a4d..ceab34bc9b 100644 --- a/tests/stdlib/trst.nim +++ b/tests/stdlib/trst.nim @@ -16,6 +16,8 @@ discard """ [Suite] RST escaping [Suite] RST inline markup + +[Suite] Misc isssues ''' matrix: "--mm:refc; --mm:orc" """ @@ -1980,3 +1982,13 @@ suite "RST inline markup": rnLeaf ')' """) check(warnings[] == @["input(1, 5) Warning: broken link 'f'"]) + +suite "Misc isssues": + test "Markdown CodeblockFields in one line (lacking enclosing ```)": + let message = """ + ```llvm-profdata merge first.profraw second.profraw third.profraw -output data.profdata```""" + + try: + echo rstgen.rstToHtml(message, {roSupportMarkdown}, nil) + except EParseError: + discard