]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Upgrade to Go 1.22.1
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 14 Mar 2024 19:25:16 +0000 (20:25 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 15 Mar 2024 15:40:36 +0000 (16:40 +0100)
Closes #12250

.circleci/config.yml
scripts/fork_go_templates/main.go
tpl/internal/go_templates/fmtsort/sort_test.go
tpl/internal/go_templates/htmltemplate/js.go
tpl/internal/go_templates/htmltemplate/js_test.go
tpl/internal/go_templates/testenv/exec.go
tpl/internal/go_templates/testenv/testenv_notunix.go
tpl/internal/go_templates/testenv/testenv_test.go
tpl/internal/go_templates/testenv/testenv_unix.go
tpl/internal/go_templates/texttemplate/parse/node.go

index a584781b00d51a9541a1e50b5d488afa74a359f7..bec0337ae39bcfb19871993fd74ee4c9c8831351 100644 (file)
@@ -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
index 5b9262c0afc3ffed0571de01c01b87a5f2eea1a9..38e81ac9ddd4d9720317dd5424bb61d73cc88201 100644 (file)
@@ -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 ...")
 
index fef952fa6095beb402965e2dd9865ae1eb2e5c1c..e86b4c673d47ed7b70ab2b9233909d4f88e11eb6 100644 (file)
@@ -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())
index 79d9102e56579c64334fffdab381a4ad0d51a08f..cc80d2b64e15186a838e462740999e6a9bdd52ed 100644 (file)
@@ -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 "</script" with "\x3C/script", and "<!--" with
+               //     "\x3C!--", which prevents confusing script block termination
+               //     semantics
+               //
+               // We also put a space before the comment so that if it is flush against
                // a division operator it is not turned into a line comment:
                //     x/{{y}}
                // turning into
                //     x//* error marshaling y:
                //          second line of error message */null
-               return fmt.Sprintf(" /* %s */null ", strings.ReplaceAll(err.Error(), "*/", "* /"))
+               errStr := err.Error()
+               errStr = strings.ReplaceAll(errStr, "*/", "* /")
+               errStr = strings.ReplaceAll(errStr, "</script", `\x3C/script`)
+               errStr = strings.ReplaceAll(errStr, "<!--", `\x3C!--`)
+               return fmt.Sprintf(" /* %s */null ", errStr)
        }
 
        // TODO: maybe post-process output to prevent it from containing
index 67a9213370b2ee1479dd44ce8df44ad84b7d9fb5..c78f43b5f7ddd206e0478cca11a1b87fb6bdc980 100644 (file)
@@ -8,6 +8,7 @@
 package template
 
 import (
+       "errors"
        "math"
        "strings"
        "testing"
@@ -106,61 +107,72 @@ func TestNextJsCtx(t *testing.T) {
        }
 }
 
+type jsonErrType struct{}
+
+func (e *jsonErrType) MarshalJSON() ([]byte, error) {
+       return nil, errors.New("beep */ boop </script blip <!--")
+}
+
 func TestJSValEscaper(t *testing.T) {
        tests := []struct {
-               x  any
-               js string
+               x        any
+               js       string
+               skipNest bool
        }{
-               {int(42), " 42 "},
-               {uint(42), " 42 "},
-               {int16(42), " 42 "},
-               {uint16(42), " 42 "},
-               {int32(-42), " -42 "},
-               {uint32(42), " 42 "},
-               {int16(-42), " -42 "},
-               {uint16(42), " 42 "},
-               {int64(-42), " -42 "},
-               {uint64(42), " 42 "},
-               {uint64(1) << 53, " 9007199254740992 "},
+               {int(42), " 42 ", false},
+               {uint(42), " 42 ", false},
+               {int16(42), " 42 ", false},
+               {uint16(42), " 42 ", false},
+               {int32(-42), " -42 ", false},
+               {uint32(42), " 42 ", false},
+               {int16(-42), " -42 ", false},
+               {uint16(42), " 42 ", false},
+               {int64(-42), " -42 ", false},
+               {uint64(42), " 42 ", false},
+               {uint64(1) << 53, " 9007199254740992 ", false},
                // ulp(1 << 53) > 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{"<!--", "</script>", "-->"}, `["\u003c!--","\u003c/script\u003e","--\u003e"]`},
-               {"<!--", `"\u003c!--"`},
-               {"-->", `"--\u003e"`},
-               {"<![CDATA[", `"\u003c![CDATA["`},
-               {"]]>", `"]]\u003e"`},
-               {"</script", `"\u003c/script"`},
-               {"\U0001D11E", "\"\U0001D11E\""}, // or "\uD834\uDD1E"
-               {nil, " null "},
+               {"\t\x0b", `"\t\u000b"`, false},
+               {struct{ X, Y int }{1, 2}, `{"X":1,"Y":2}`, false},
+               {[]any{}, "[]", false},
+               {[]any{42, "foo", nil}, `[42,"foo",null]`, false},
+               {[]string{"<!--", "</script>", "-->"}, `["\u003c!--","\u003c/script\u003e","--\u003e"]`, false},
+               {"<!--", `"\u003c!--"`, false},
+               {"-->", `"--\u003e"`, false},
+               {"<![CDATA[", `"\u003c![CDATA["`, false},
+               {"]]>", `"]]\u003e"`, false},
+               {"</script", `"\u003c/script"`, false},
+               {"\U0001D11E", "\"\U0001D11E\"", false}, // or "\uD834\uDD1E"
+               {nil, " null ", false},
+               {&jsonErrType{}, " /* json: error calling MarshalJSON for type *template.jsonErrType: beep * / boop \\x3C/script blip \\x3C!-- */null ", true},
        }
 
        for _, test := range tests {
                if js := jsValEscaper(test.x); js != test.js {
                        t.Errorf("%+v: want\n\t%q\ngot\n\t%q", test.x, test.js, js)
                }
+               if test.skipNest {
+                       continue
+               }
                // Make sure that escaping corner cases are not broken
                // by nesting.
                a := []any{test.x}
index 14460224800bdaa1ab988c2a3cbd80f820e97104..7f6ad5cac4e39b603c0f59b797ff84c926a5bc5d 100644 (file)
@@ -6,6 +6,7 @@ package testenv
 
 import (
        "context"
+       "errors"
        "fmt"
        "os"
        "os/exec"
@@ -60,6 +61,13 @@ func tryExec() error {
        // may as well use the same path so that this branch can be tested without
        // an ios environment.
 
+       if !testing.Testing() {
+               // This isn't a standard 'go test' binary, so we don't know how to
+               // self-exec in a way that should succeed without side effects.
+               // Just forget it.
+               return errors.New("can't probe for exec support with a non-test executable")
+       }
+
        // We know that this is a test executable. We should be able to run it with a
        // no-op flag to check for overall exec support.
        exe, err := os.Executable()
index 916f1815379cb2d46471a4ea2ad9bdfc0767b4a6..a7df5f5ddcecea267bccc61cabd74a25a4d80312 100644 (file)
@@ -17,5 +17,5 @@ import (
 var Sigquit = os.Kill
 
 func syscallIsNotSupported(err error) bool {
-       return errors.Is(err, fs.ErrPermission)
+       return errors.Is(err, fs.ErrPermission) || errors.Is(err, errors.ErrUnsupported)
 }
index 13e11abfb534b0d82d3e094e10424cec29d51451..d4b2b368f3730cde86acabd9596488f8b7645f01 100644 (file)
@@ -54,8 +54,8 @@ func TestGoToolLocation(t *testing.T) {
        }
 }
 
+// Modified by Hugo.
 func TestHasGoBuild(t *testing.T) {
-       // Removed by Hugo.
 }
 
 func TestMustHaveExec(t *testing.T) {
@@ -73,7 +73,7 @@ func TestMustHaveExec(t *testing.T) {
                        t.Errorf("expected MustHaveExec to skip on %v", runtime.GOOS)
                }
        case "ios":
-               if b := testenv.Builder(); strings.HasSuffix(b, "-corellium") && !hasExec {
+               if b := testenv.Builder(); isCorelliumBuilder(b) && !hasExec {
                        // Most ios environments can't exec, but the corellium builder can.
                        t.Errorf("expected MustHaveExec not to skip on %v", b)
                }
@@ -106,3 +106,23 @@ func TestCleanCmdEnvPWD(t *testing.T) {
        }
        t.Error("PWD not set in cmd.Env")
 }
+
+func isCorelliumBuilder(builderName string) bool {
+       // Support both the old infra's builder names and the LUCI builder names.
+       // The former's names are ad-hoc so we could maintain this invariant on
+       // the builder side. The latter's names are structured, and "corellium" will
+       // appear as a "host" suffix after the GOOS and GOARCH, which always begin
+       // with an underscore.
+       return strings.HasSuffix(builderName, "-corellium") || strings.Contains(builderName, "_corellium")
+}
+
+func isEmulatedBuilder(builderName string) bool {
+       // Support both the old infra's builder names and the LUCI builder names.
+       // The former's names are ad-hoc so we could maintain this invariant on
+       // the builder side. The latter's names are structured, and the signifier
+       // of emulation "emu" will appear as a "host" suffix after the GOOS and
+       // GOARCH because it modifies the run environment in such a way that it
+       // the target GOOS and GOARCH may not match the host. This suffix always
+       // begins with an underscore.
+       return strings.HasSuffix(builderName, "-emu") || strings.Contains(builderName, "_emu")
+}
index 296eefc7a711c68f855ee3e3a9598df4614a1baf..a629078842eadcbb904dd354fe5567ea8a28300f 100644 (file)
@@ -35,7 +35,7 @@ func syscallIsNotSupported(err error) bool {
                }
        }
 
-       if errors.Is(err, fs.ErrPermission) {
+       if errors.Is(err, fs.ErrPermission) || errors.Is(err, errors.ErrUnsupported) {
                return true
        }
 
index 47268225c8ca1cd4aef1f4cc5e4bd4c9d0543904..c36688825c200c2c415996b6a04b5944ce6a469d 100644 (file)
@@ -284,7 +284,6 @@ func (a *ActionNode) tree() *Tree {
 
 func (a *ActionNode) Copy() Node {
        return a.tr.newAction(a.Pos, a.Line, a.Pipe.CopyPipe())
-
 }
 
 // CommandNode holds a command (a pipeline inside an evaluating action).