mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
present: check if too few arguments to image, iframe, or video
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>
This commit is contained in:
parent
e96d959c47
commit
b2104f82a9
@ -23,6 +23,9 @@ func (i Iframe) TemplateName() string { return "iframe" }
|
|||||||
|
|
||||||
func parseIframe(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
|
func parseIframe(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
|
||||||
args := strings.Fields(text)
|
args := strings.Fields(text)
|
||||||
|
if len(args) < 2 {
|
||||||
|
return nil, fmt.Errorf("incorrect iframe invocation: %q", text)
|
||||||
|
}
|
||||||
i := Iframe{URL: args[1]}
|
i := Iframe{URL: args[1]}
|
||||||
a, err := parseArgs(fileName, lineno, args[2:])
|
a, err := parseArgs(fileName, lineno, args[2:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -23,6 +23,9 @@ func (i Image) TemplateName() string { return "image" }
|
|||||||
|
|
||||||
func parseImage(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
|
func parseImage(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
|
||||||
args := strings.Fields(text)
|
args := strings.Fields(text)
|
||||||
|
if len(args) < 2 {
|
||||||
|
return nil, fmt.Errorf("incorrect image invocation: %q", text)
|
||||||
|
}
|
||||||
img := Image{URL: args[1]}
|
img := Image{URL: args[1]}
|
||||||
a, err := parseArgs(fileName, lineno, args[2:])
|
a, err := parseArgs(fileName, lineno, args[2:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -24,6 +24,9 @@ func (v Video) TemplateName() string { return "video" }
|
|||||||
|
|
||||||
func parseVideo(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
|
func parseVideo(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
|
||||||
args := strings.Fields(text)
|
args := strings.Fields(text)
|
||||||
|
if len(args) < 3 {
|
||||||
|
return nil, fmt.Errorf("incorrect video invocation: %q", text)
|
||||||
|
}
|
||||||
vid := Video{URL: args[1], SourceType: args[2]}
|
vid := Video{URL: args[1], SourceType: args[2]}
|
||||||
a, err := parseArgs(fileName, lineno, args[3:])
|
a, err := parseArgs(fileName, lineno, args[3:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user