fixes whitespace related endless loop in renderer.nim (#25750)

(cherry picked from commit b4d4028afa)
This commit is contained in:
Andreas Rumpf
2026-04-16 09:44:58 +02:00
committed by narimiran
parent 2d3c436228
commit 3b02151581
2 changed files with 12 additions and 2 deletions

View File

@@ -229,6 +229,7 @@ proc put(g: var TSrcGen, kind: TokType, s: string; sym: PSym = nil) =
inc(g.lineLen, s.len)
proc putComment(g: var TSrcGen, s: string) =
const SpecialWhitespace = {' ', '\t', '\r', '\n', '\0'}
if s.len == 0: return
var i = 0
let hi = s.len - 1
@@ -258,12 +259,12 @@ proc putComment(g: var TSrcGen, s: string) =
# gets too long:
# compute length of the following word:
var j = i
while j <= hi and s[j] > ' ': inc(j)
while j <= hi and s[j] notin SpecialWhitespace: inc(j)
if not isCode and (g.col + (j - i) > MaxLineLen):
put(g, tkComment, com)
optNL(g, ind)
com = "## "
while i <= hi and s[i] > ' ':
while i <= hi and s[i] notin SpecialWhitespace:
com.add(s[i])
inc(i)
put(g, tkComment, com)

View File

@@ -350,3 +350,12 @@ else:
discard"""
a()
# bug: form feed character in comment should not hang renderTree
macro formfeedComment(): untyped =
result = newNimNode(nnkStmtList)
var c = newNimNode(nnkCommentStmt)
c.strVal = "hello\x0Cworld"
result.add c
formfeedComment()