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 <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/src/go/doc/comment.go b/src/go/doc/comment.go
index da33f21..92131a3 100644
--- a/src/go/doc/comment.go
+++ b/src/go/doc/comment.go
@@ -487,7 +487,7 @@
 			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 101f446..6d1b209 100644
--- a/src/go/doc/comment_test.go
+++ b/src/go/doc/comment_test.go
@@ -154,6 +154,17 @@
 .   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 //
+`,
+	},
 }
 
 func TestBlocks(t *testing.T) {