]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/doc: adding validation before adding comment marker
authorkemalelmizan <kemalelmizan@gmail.com>
Thu, 27 Aug 2020 23:39:43 +0000 (06:39 +0700)
committerRobert Griesemer <gri@golang.org>
Tue, 3 Nov 2020 01:27:45 +0000 (01:27 +0000)
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>

src/go/doc/comment.go
src/go/doc/comment_test.go

index da33f21612feec04ff295fadf4c2b7563686ceb9..92131a3b83f02700cb4b48d21d2ed3947056c082 100644 (file)
@@ -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))
index 101f4462878b9d05a8be1dd80e8d861659283c67..6d1b209e1e1f983494a5a01eb70a6b06e4398349 100644 (file)
@@ -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 //
 `,
        },
 }