1
0
mirror of https://github.com/golang/go synced 2024-11-17 09:54:46 -07:00

go/doc/comment: don't crash if there are no words to wrap

Fixes #52783

Change-Id: I12e3da40d49cd92776052bf19cb07ee8a07f3ee0
Reviewed-on: https://go-review.googlesource.com/c/go/+/405215
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Ian Lance Taylor 2022-05-09 13:23:10 -07:00 committed by Gopher Robot
parent a971499a62
commit 3f43096f15
2 changed files with 17 additions and 1 deletions

16
src/go/doc/comment/testdata/crash1.txt vendored Normal file
View File

@ -0,0 +1,16 @@
-- input --
[]
[]: http://
-- gofmt --
[]
[]: http://
-- html --
<p><a href="http://"></a>
-- markdown --
[](http://)
-- text --
[]: http://

View File

@ -141,7 +141,7 @@ func (p *textPrinter) text(out *bytes.Buffer, indent string, x []Text) {
p.long.Reset()
var seq []int
if p.width < 0 {
if p.width < 0 || len(words) == 0 {
seq = []int{0, len(words)} // one long line
} else {
seq = wrap(words, p.width-utf8.RuneCountInString(indent))