From 57206e72749966f36c6e731c3f5ce7d9b5b11464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 14 Mar 2024 20:25:16 +0100 Subject: [PATCH] Upgrade to Go 1.22.1 Closes #12250 --- .circleci/config.yml | 4 +- scripts/fork_go_templates/main.go | 3 +- .../go_templates/fmtsort/sort_test.go | 8 +- tpl/internal/go_templates/htmltemplate/js.go | 22 ++++- .../go_templates/htmltemplate/js_test.go | 96 +++++++++++-------- tpl/internal/go_templates/testenv/exec.go | 8 ++ .../go_templates/testenv/testenv_notunix.go | 2 +- .../go_templates/testenv/testenv_test.go | 24 ++++- .../go_templates/testenv/testenv_unix.go | 2 +- .../go_templates/texttemplate/parse/node.go | 1 - 10 files changed, 114 insertions(+), 56 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a584781b0..bec0337ae 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,7 @@ parameters: defaults: &defaults resource_class: large docker: - - image: bepsays/ci-hugoreleaser:1.22200.20000 + - image: bepsays/ci-hugoreleaser:1.22200.20100 environment: &buildenv GOMODCACHE: /root/project/gomodcache version: 2 @@ -60,7 +60,7 @@ jobs: environment: <<: [*buildenv] docker: - - image: bepsays/ci-hugoreleaser-linux-arm64:1.22200.20000 + - image: bepsays/ci-hugoreleaser-linux-arm64:1.22200.20100 steps: - *restore-cache - &attach-workspace diff --git a/scripts/fork_go_templates/main.go b/scripts/fork_go_templates/main.go index 5b9262c0a..38e81ac9d 100644 --- a/scripts/fork_go_templates/main.go +++ b/scripts/fork_go_templates/main.go @@ -16,7 +16,8 @@ import ( ) func main() { - // The current is built with 446a5dcf5a3230ce9832682d8f521071d8a34a2b (go 1.22 dev. Thu Oct 5 12:20:11 2023 -0700) + // The current is built with db6097f8cb [release-branch.go1.22] go1.22.1 + // TODO(bep) preserve the staticcheck.conf file. fmt.Println("Forking ...") defer fmt.Println("Done ...") diff --git a/tpl/internal/go_templates/fmtsort/sort_test.go b/tpl/internal/go_templates/fmtsort/sort_test.go index fef952fa6..e86b4c673 100644 --- a/tpl/internal/go_templates/fmtsort/sort_test.go +++ b/tpl/internal/go_templates/fmtsort/sort_test.go @@ -6,14 +6,14 @@ package fmtsort_test import ( "fmt" + "github.com/gohugoio/hugo/tpl/internal/go_templates/fmtsort" "math" "reflect" + "runtime" "sort" "strings" "testing" "unsafe" - - "github.com/gohugoio/hugo/tpl/internal/go_templates/fmtsort" ) var compareTests = [][]reflect.Value{ @@ -191,14 +191,14 @@ func sprintKey(key reflect.Value) string { var ( ints [3]int chans = makeChans() - // pin runtime.Pinner + pin runtime.Pinner ) func makeChans() []chan int { cs := []chan int{make(chan int), make(chan int), make(chan int)} // Order channels by address. See issue #49431. for i := range cs { - reflect.ValueOf(cs[i]).UnsafePointer() + pin.Pin(reflect.ValueOf(cs[i]).UnsafePointer()) } sort.Slice(cs, func(i, j int) bool { return uintptr(reflect.ValueOf(cs[i]).UnsafePointer()) < uintptr(reflect.ValueOf(cs[j]).UnsafePointer()) diff --git a/tpl/internal/go_templates/htmltemplate/js.go b/tpl/internal/go_templates/htmltemplate/js.go index 79d9102e5..cc80d2b64 100644 --- a/tpl/internal/go_templates/htmltemplate/js.go +++ b/tpl/internal/go_templates/htmltemplate/js.go @@ -172,13 +172,31 @@ func jsValEscaper(args ...any) string { // cyclic data. This may be an unacceptable DoS risk. b, err := json.Marshal(a) if err != nil { - // Put a space before comment so that if it is flush against + // While the standard JSON marshaller does not include user controlled + // information in the error message, if a type has a MarshalJSON method, + // the content of the error message is not guaranteed. Since we insert + // the error into the template, as part of a comment, we attempt to + // prevent the error from either terminating the comment, or the script + // block itself. + // + // In particular we: + // * replace "*/" comment end tokens with "* /", which does not + // terminate the comment + // * replace " 1 so this loses precision in JS // but it is still a representable integer literal. - {uint64(1)<<53 + 1, " 9007199254740993 "}, - {float32(1.0), " 1 "}, - {float32(-1.0), " -1 "}, - {float32(0.5), " 0.5 "}, - {float32(-0.5), " -0.5 "}, - {float32(1.0) / float32(256), " 0.00390625 "}, - {float32(0), " 0 "}, - {math.Copysign(0, -1), " -0 "}, - {float64(1.0), " 1 "}, - {float64(-1.0), " -1 "}, - {float64(0.5), " 0.5 "}, - {float64(-0.5), " -0.5 "}, - {float64(0), " 0 "}, - {math.Copysign(0, -1), " -0 "}, - {"", `""`}, - {"foo", `"foo"`}, + {uint64(1)<<53 + 1, " 9007199254740993 ", false}, + {float32(1.0), " 1 ", false}, + {float32(-1.0), " -1 ", false}, + {float32(0.5), " 0.5 ", false}, + {float32(-0.5), " -0.5 ", false}, + {float32(1.0) / float32(256), " 0.00390625 ", false}, + {float32(0), " 0 ", false}, + {math.Copysign(0, -1), " -0 ", false}, + {float64(1.0), " 1 ", false}, + {float64(-1.0), " -1 ", false}, + {float64(0.5), " 0.5 ", false}, + {float64(-0.5), " -0.5 ", false}, + {float64(0), " 0 ", false}, + {math.Copysign(0, -1), " -0 ", false}, + {"", `""`, false}, + {"foo", `"foo"`, false}, // Newlines. - {"\r\n\u2028\u2029", `"\r\n\u2028\u2029"`}, + {"\r\n\u2028\u2029", `"\r\n\u2028\u2029"`, false}, // "\v" == "v" on IE 6 so use "\u000b" instead. - {"\t\x0b", `"\t\u000b"`}, - {struct{ X, Y int }{1, 2}, `{"X":1,"Y":2}`}, - {[]any{}, "[]"}, - {[]any{42, "foo", nil}, `[42,"foo",null]`}, - {[]string{""}, `["\u003c!--","\u003c/script\u003e","--\u003e"]`}, - {"", `"--\u003e"`}, - {"", `"]]\u003e"`}, - {"", "-->"}, `["\u003c!--","\u003c/script\u003e","--\u003e"]`, false}, + {"", `"--\u003e"`, false}, + {"", `"]]\u003e"`, false}, + {"