From 3f43096f1549ea32229202618d9cd81a5761c697 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 9 May 2022 13:23:10 -0700 Subject: [PATCH] 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 Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills Reviewed-by: Heschi Kreinick --- src/go/doc/comment/testdata/crash1.txt | 16 ++++++++++++++++ src/go/doc/comment/text.go | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/go/doc/comment/testdata/crash1.txt diff --git a/src/go/doc/comment/testdata/crash1.txt b/src/go/doc/comment/testdata/crash1.txt new file mode 100644 index 0000000000..6bb2f6fdda --- /dev/null +++ b/src/go/doc/comment/testdata/crash1.txt @@ -0,0 +1,16 @@ +-- input -- +[] + +[]: http:// +-- gofmt -- +[] + +[]: http:// +-- html -- +

+-- markdown -- +[](http://) +-- text -- + + +[]: http:// diff --git a/src/go/doc/comment/text.go b/src/go/doc/comment/text.go index e9684f066b..86e5eebe9a 100644 --- a/src/go/doc/comment/text.go +++ b/src/go/doc/comment/text.go @@ -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)) -- 2.50.0