1
0
mirror of https://github.com/golang/go synced 2024-11-17 10:44:43 -07:00

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>
This commit is contained in:
kemalelmizan 2020-08-28 06:39:43 +07:00 committed by Robert Griesemer
parent 45205bc47b
commit cc0930cd1d
2 changed files with 12 additions and 1 deletions

View File

@ -487,7 +487,7 @@ func (l *lineWrapper) write(text string) {
l.out.Write(nl) l.out.Write(nl)
l.n = 0 l.n = 0
l.pendSpace = 0 l.pendSpace = 0
needsPrefix = isComment needsPrefix = isComment && !strings.HasPrefix(f, "//")
} }
if l.n == 0 { if l.n == 0 {
l.out.Write([]byte(l.indent)) l.out.Write([]byte(l.indent))

View 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 text: `. /* A very long line of 46 char for line
. wrapping. A very long line of 46 char . wrapping. A very long line of 46 char
. for line wrapping. */ . 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 //
`, `,
}, },
} }