]> Cypherpunks repositories - gostls13.git/commitdiff
go/doc/comment: don't crash if there are no words to wrap
authorIan Lance Taylor <iant@golang.org>
Mon, 9 May 2022 20:23:10 +0000 (13:23 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 9 May 2022 20:57:58 +0000 (20:57 +0000)
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>
src/go/doc/comment/testdata/crash1.txt [new file with mode: 0644]
src/go/doc/comment/text.go

diff --git a/src/go/doc/comment/testdata/crash1.txt b/src/go/doc/comment/testdata/crash1.txt
new file mode 100644 (file)
index 0000000..6bb2f6f
--- /dev/null
@@ -0,0 +1,16 @@
+-- input --
+[]
+
+[]: http://
+-- gofmt --
+[]
+
+[]: http://
+-- html --
+<p><a href="http://"></a>
+-- markdown --
+[](http://)
+-- text --
+
+
+[]: http://
index e9684f066bfb1fff2706185e3b9a00c9dfc8d742..86e5eebe9a2d0025a4377acf976e6902791fe8e7 100644 (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))