mirror of
https://github.com/golang/go
synced 2024-11-21 23:54:40 -07:00
godoc: proper index range checking when extracting example code
Fixes #3092. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5683075
This commit is contained in:
parent
024df9f6c4
commit
775f0058ac
@ -524,11 +524,11 @@ func example_htmlFunc(funcName string, examples []*doc.Example, fset *token.File
|
|||||||
out := eg.Output
|
out := eg.Output
|
||||||
|
|
||||||
// additional formatting if this is a function body
|
// additional formatting if this is a function body
|
||||||
if len(code) > 0 && code[0] == '{' {
|
if n := len(code); n >= 2 && code[0] == '{' && code[n-1] == '}' {
|
||||||
|
// remove surrounding braces
|
||||||
|
code = code[1 : n-1]
|
||||||
// unindent
|
// unindent
|
||||||
code = strings.Replace(code, "\n ", "\n", -1)
|
code = strings.Replace(code, "\n ", "\n", -1)
|
||||||
// remove surrounding braces
|
|
||||||
code = code[2 : len(code)-2]
|
|
||||||
// remove output comment
|
// remove output comment
|
||||||
if loc := exampleOutputRx.FindStringIndex(code); loc != nil {
|
if loc := exampleOutputRx.FindStringIndex(code); loc != nil {
|
||||||
code = strings.TrimSpace(code[:loc[0]])
|
code = strings.TrimSpace(code[:loc[0]])
|
||||||
|
Loading…
Reference in New Issue
Block a user