mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
tpl: Sync go_templates for Go 1.18
Using Go tag go1.18 4aa1efed4853ea067d665a952eee77c52faac774 Updates #9677
This commit is contained in:
@@ -123,7 +123,7 @@ var jsonMarshalType = reflect.TypeOf((*json.Marshaler)(nil)).Elem()
|
||||
|
||||
// indirectToJSONMarshaler returns the value, after dereferencing as many times
|
||||
// as necessary to reach the base type (or nil) or an implementation of json.Marshal.
|
||||
func indirectToJSONMarshaler(a interface{}) interface{} {
|
||||
func indirectToJSONMarshaler(a any) any {
|
||||
// text/template now supports passing untyped nil as a func call
|
||||
// argument, so we must support it. Otherwise we'd panic below, as one
|
||||
// cannot call the Type or Interface methods on an invalid
|
||||
@@ -133,7 +133,7 @@ func indirectToJSONMarshaler(a interface{}) interface{} {
|
||||
}
|
||||
|
||||
v := reflect.ValueOf(a)
|
||||
for !v.Type().Implements(jsonMarshalType) && v.Kind() == reflect.Ptr && !v.IsNil() {
|
||||
for !v.Type().Implements(jsonMarshalType) && v.Kind() == reflect.Pointer && !v.IsNil() {
|
||||
v = v.Elem()
|
||||
}
|
||||
return v.Interface()
|
||||
@@ -141,8 +141,8 @@ func indirectToJSONMarshaler(a interface{}) interface{} {
|
||||
|
||||
// jsValEscaper escapes its inputs to a JS Expression (section 11.14) that has
|
||||
// neither side-effects nor free variables outside (NaN, Infinity).
|
||||
func jsValEscaper(args ...interface{}) string {
|
||||
var a interface{}
|
||||
func jsValEscaper(args ...any) string {
|
||||
var a any
|
||||
if len(args) == 1 {
|
||||
a = indirectToJSONMarshaler(args[0])
|
||||
switch t := a.(type) {
|
||||
@@ -225,7 +225,7 @@ func jsValEscaper(args ...interface{}) string {
|
||||
// jsStrEscaper produces a string that can be included between quotes in
|
||||
// JavaScript source, in JavaScript embedded in an HTML5 <script> element,
|
||||
// or in an HTML5 event handler attribute such as onclick.
|
||||
func jsStrEscaper(args ...interface{}) string {
|
||||
func jsStrEscaper(args ...any) string {
|
||||
s, t := stringify(args...)
|
||||
if t == contentTypeJSStr {
|
||||
return replace(s, jsStrNormReplacementTable)
|
||||
@@ -237,7 +237,7 @@ func jsStrEscaper(args ...interface{}) string {
|
||||
// specials so the result is treated literally when included in a regular
|
||||
// expression literal. /foo{{.X}}bar/ matches the string "foo" followed by
|
||||
// the literal text of {{.X}} followed by the string "bar".
|
||||
func jsRegexpEscaper(args ...interface{}) string {
|
||||
func jsRegexpEscaper(args ...any) string {
|
||||
s, _ := stringify(args...)
|
||||
s = replace(s, jsRegexpReplacementTable)
|
||||
if s == "" {
|
||||
@@ -399,9 +399,7 @@ func isJSType(mimeType string) bool {
|
||||
// https://tools.ietf.org/html/rfc4329#section-3
|
||||
// https://www.ietf.org/rfc/rfc4627.txt
|
||||
// discard parameters
|
||||
if i := strings.Index(mimeType, ";"); i >= 0 {
|
||||
mimeType = mimeType[:i]
|
||||
}
|
||||
mimeType, _, _ = strings.Cut(mimeType, ";")
|
||||
mimeType = strings.ToLower(mimeType)
|
||||
mimeType = strings.TrimSpace(mimeType)
|
||||
switch mimeType {
|
||||
|
Reference in New Issue
Block a user