Commit 775f0058 authored by Robert Griesemer's avatar Robert Griesemer

godoc: proper index range checking when extracting example code

Fixes #3092.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5683075
parent 024df9f6
......@@ -524,11 +524,11 @@ func example_htmlFunc(funcName string, examples []*doc.Example, fset *token.File
out := eg.Output
// 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
code = strings.Replace(code, "\n ", "\n", -1)
// remove surrounding braces
code = code[2 : len(code)-2]
// remove output comment
if loc := exampleOutputRx.FindStringIndex(code); loc != nil {
code = strings.TrimSpace(code[:loc[0]])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment