// Copyright 2011 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 template import ( "fmt" "text/template/parse" ) // Error describes a problem encountered during template Escaping. type Error struct { // ErrorCode describes the kind of error. ErrorCode ErrorCode // Node is the node that caused the problem, if known. // If not nil, it overrides Name and Line. Node parse.Node // Name is the name of the template in which the error was encountered. Name string // Line is the line number of the error in the template source or 0. Line int // Description is a human-readable description of the problem. Description string } // ErrorCode is a code for a kind of error. type ErrorCode int // We define codes for each error that manifests while escaping templates, but // escaped templates may also fail at runtime. // // Output: "ZgotmplZ" // Example: // // where {{.X}} evaluates to `javascript:...` // Discussion: // "ZgotmplZ" is a special value that indicates that unsafe content reached a // CSS or URL context at runtime. The output of the example will be // // If the data comes from a trusted source, use content types to exempt it // from filtering: URL(`javascript:...`). const ( // OK indicates the lack of an error. OK ErrorCode = iota // ErrAmbigContext: "... appears in an ambiguous URL context" // Example: // // Discussion: // {{.X}} is in an ambiguous URL context since, depending on {{.C}}, // it may be either a URL suffix or a query parameter. // Moving {{.X}} into the condition removes the ambiguity: // ErrAmbigContext // ErrBadHTML: "expected space, attr name, or end of tag, but got ...", // "... in unquoted attr", "... in attribute name" // Example: // // //
//