From cc0930cd1d200a126a3ae8ac3d1bea986cfc30fe Mon Sep 17 00:00:00 2001 From: kemalelmizan Date: Fri, 28 Aug 2020 06:39:43 +0700 Subject: [PATCH] cmd/doc: adding validation before adding comment marker Previous fix in issue #20929 for adding comment marker does not check whether string field have // prefix or not. This commit ensures string field does not contain // before adding prefix to the line. Test also included in this commit. Fixes #40992 Change-Id: Ibc5e8ef147eeb2ed732fb9e19815c8b21fcfb2ab Reviewed-on: https://go-review.googlesource.com/c/go/+/251237 Run-TryBot: Robert Griesemer TryBot-Result: Go Bot Reviewed-by: Robert Griesemer Trust: Robert Griesemer Trust: Dmitri Shuralyov --- src/go/doc/comment.go | 2 +- src/go/doc/comment_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/go/doc/comment.go b/src/go/doc/comment.go index da33f21612f..92131a3b83f 100644 --- a/src/go/doc/comment.go +++ b/src/go/doc/comment.go @@ -487,7 +487,7 @@ func (l *lineWrapper) write(text string) { l.out.Write(nl) l.n = 0 l.pendSpace = 0 - needsPrefix = isComment + needsPrefix = isComment && !strings.HasPrefix(f, "//") } if l.n == 0 { l.out.Write([]byte(l.indent)) diff --git a/src/go/doc/comment_test.go b/src/go/doc/comment_test.go index 101f4462878..6d1b209e1e1 100644 --- a/src/go/doc/comment_test.go +++ b/src/go/doc/comment_test.go @@ -152,6 +152,17 @@ A very long line of 46 char for line wrapping. */`, text: `. /* A very long line of 46 char for line . wrapping. A very long line of 46 char . for line wrapping. */ +`, + }, + { + in: `A line of 36 char for line wrapping. +//Another line starting with //`, + out: []block{ + {opPara, []string{"A line of 36 char for line wrapping.\n", + "//Another line starting with //"}}, + }, + text: `. A line of 36 char for line wrapping. +. //Another line starting with // `, }, }