mirror of
https://github.com/golang/go
synced 2024-11-05 19:46:11 -07:00
b2104f82a9
Previously, using incorrect syntax for one of image, iframe, or video functions caused an index out of range panic. Add a check to prevent the panic and return an error instead. Fixes golang/go#35142 Change-Id: Ifffb4cc5daded5331d617a3db7cad84e37abadc8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/203477 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
49 lines
957 B
Go
49 lines
957 B
Go
// Copyright 2013 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package present
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func init() {
|
|
Register("iframe", parseIframe)
|
|
}
|
|
|
|
type Iframe struct {
|
|
URL string
|
|
Width int
|
|
Height int
|
|
}
|
|
|
|
func (i Iframe) TemplateName() string { return "iframe" }
|
|
|
|
func parseIframe(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
|
|
args := strings.Fields(text)
|
|
if len(args) < 2 {
|
|
return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
|
|
}
|
|
i := Iframe{URL: args[1]}
|
|
a, err := parseArgs(fileName, lineno, args[2:])
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
switch len(a) {
|
|
case 0:
|
|
// no size parameters
|
|
case 2:
|
|
if v, ok := a[0].(int); ok {
|
|
i.Height = v
|
|
}
|
|
if v, ok := a[1].(int); ok {
|
|
i.Width = v
|
|
}
|
|
default:
|
|
return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
|
|
}
|
|
return i, nil
|
|
}
|