Skip to content

Commit 57206e7

Browse files
committed
Upgrade to Go 1.22.1
Closes gohugoio#12250
1 parent b1f8676 commit 57206e7

File tree

10 files changed

+114
-56
lines changed

10 files changed

+114
-56
lines changed

.circleci/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ parameters:
44
defaults: &defaults
55
resource_class: large
66
docker:
7-
- image: bepsays/ci-hugoreleaser:1.22200.20000
7+
- image: bepsays/ci-hugoreleaser:1.22200.20100
88
environment: &buildenv
99
GOMODCACHE: /root/project/gomodcache
1010
version: 2
@@ -60,7 +60,7 @@ jobs:
6060
environment:
6161
<<: [*buildenv]
6262
docker:
63-
- image: bepsays/ci-hugoreleaser-linux-arm64:1.22200.20000
63+
- image: bepsays/ci-hugoreleaser-linux-arm64:1.22200.20100
6464
steps:
6565
- *restore-cache
6666
- &attach-workspace

scripts/fork_go_templates/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import (
1616
)
1717

1818
func main() {
19-
// The current is built with 446a5dcf5a3230ce9832682d8f521071d8a34a2b (go 1.22 dev. Thu Oct 5 12:20:11 2023 -0700)
19+
// The current is built with db6097f8cb [release-branch.go1.22] go1.22.1
20+
// TODO(bep) preserve the staticcheck.conf file.
2021
fmt.Println("Forking ...")
2122
defer fmt.Println("Done ...")
2223

tpl/internal/go_templates/fmtsort/sort_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ package fmtsort_test
66

77
import (
88
"fmt"
9+
"github.com/gohugoio/hugo/tpl/internal/go_templates/fmtsort"
910
"math"
1011
"reflect"
12+
"runtime"
1113
"sort"
1214
"strings"
1315
"testing"
1416
"unsafe"
15-
16-
"github.com/gohugoio/hugo/tpl/internal/go_templates/fmtsort"
1717
)
1818

1919
var compareTests = [][]reflect.Value{
@@ -191,14 +191,14 @@ func sprintKey(key reflect.Value) string {
191191
var (
192192
ints [3]int
193193
chans = makeChans()
194-
// pin runtime.Pinner
194+
pin runtime.Pinner
195195
)
196196

197197
func makeChans() []chan int {
198198
cs := []chan int{make(chan int), make(chan int), make(chan int)}
199199
// Order channels by address. See issue #49431.
200200
for i := range cs {
201-
reflect.ValueOf(cs[i]).UnsafePointer()
201+
pin.Pin(reflect.ValueOf(cs[i]).UnsafePointer())
202202
}
203203
sort.Slice(cs, func(i, j int) bool {
204204
return uintptr(reflect.ValueOf(cs[i]).UnsafePointer()) < uintptr(reflect.ValueOf(cs[j]).UnsafePointer())

tpl/internal/go_templates/htmltemplate/js.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,31 @@ func jsValEscaper(args ...any) string {
172172
// cyclic data. This may be an unacceptable DoS risk.
173173
b, err := json.Marshal(a)
174174
if err != nil {
175-
// Put a space before comment so that if it is flush against
175+
// While the standard JSON marshaller does not include user controlled
176+
// information in the error message, if a type has a MarshalJSON method,
177+
// the content of the error message is not guaranteed. Since we insert
178+
// the error into the template, as part of a comment, we attempt to
179+
// prevent the error from either terminating the comment, or the script
180+
// block itself.
181+
//
182+
// In particular we:
183+
// * replace "*/" comment end tokens with "* /", which does not
184+
// terminate the comment
185+
// * replace "</script" with "\x3C/script", and "<!--" with
186+
// "\x3C!--", which prevents confusing script block termination
187+
// semantics
188+
//
189+
// We also put a space before the comment so that if it is flush against
176190
// a division operator it is not turned into a line comment:
177191
// x/{{y}}
178192
// turning into
179193
// x//* error marshaling y:
180194
// second line of error message */null
181-
return fmt.Sprintf(" /* %s */null ", strings.ReplaceAll(err.Error(), "*/", "* /"))
195+
errStr := err.Error()
196+
errStr = strings.ReplaceAll(errStr, "*/", "* /")
197+
errStr = strings.ReplaceAll(errStr, "</script", `\x3C/script`)
198+
errStr = strings.ReplaceAll(errStr, "<!--", `\x3C!--`)
199+
return fmt.Sprintf(" /* %s */null ", errStr)
182200
}
183201

184202
// TODO: maybe post-process output to prevent it from containing

tpl/internal/go_templates/htmltemplate/js_test.go

+54-42
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package template
99

1010
import (
11+
"errors"
1112
"math"
1213
"strings"
1314
"testing"
@@ -106,61 +107,72 @@ func TestNextJsCtx(t *testing.T) {
106107
}
107108
}
108109

110+
type jsonErrType struct{}
111+
112+
func (e *jsonErrType) MarshalJSON() ([]byte, error) {
113+
return nil, errors.New("beep */ boop </script blip <!--")
114+
}
115+
109116
func TestJSValEscaper(t *testing.T) {
110117
tests := []struct {
111-
x any
112-
js string
118+
x any
119+
js string
120+
skipNest bool
113121
}{
114-
{int(42), " 42 "},
115-
{uint(42), " 42 "},
116-
{int16(42), " 42 "},
117-
{uint16(42), " 42 "},
118-
{int32(-42), " -42 "},
119-
{uint32(42), " 42 "},
120-
{int16(-42), " -42 "},
121-
{uint16(42), " 42 "},
122-
{int64(-42), " -42 "},
123-
{uint64(42), " 42 "},
124-
{uint64(1) << 53, " 9007199254740992 "},
122+
{int(42), " 42 ", false},
123+
{uint(42), " 42 ", false},
124+
{int16(42), " 42 ", false},
125+
{uint16(42), " 42 ", false},
126+
{int32(-42), " -42 ", false},
127+
{uint32(42), " 42 ", false},
128+
{int16(-42), " -42 ", false},
129+
{uint16(42), " 42 ", false},
130+
{int64(-42), " -42 ", false},
131+
{uint64(42), " 42 ", false},
132+
{uint64(1) << 53, " 9007199254740992 ", false},
125133
// ulp(1 << 53) > 1 so this loses precision in JS
126134
// but it is still a representable integer literal.
127-
{uint64(1)<<53 + 1, " 9007199254740993 "},
128-
{float32(1.0), " 1 "},
129-
{float32(-1.0), " -1 "},
130-
{float32(0.5), " 0.5 "},
131-
{float32(-0.5), " -0.5 "},
132-
{float32(1.0) / float32(256), " 0.00390625 "},
133-
{float32(0), " 0 "},
134-
{math.Copysign(0, -1), " -0 "},
135-
{float64(1.0), " 1 "},
136-
{float64(-1.0), " -1 "},
137-
{float64(0.5), " 0.5 "},
138-
{float64(-0.5), " -0.5 "},
139-
{float64(0), " 0 "},
140-
{math.Copysign(0, -1), " -0 "},
141-
{"", `""`},
142-
{"foo", `"foo"`},
135+
{uint64(1)<<53 + 1, " 9007199254740993 ", false},
136+
{float32(1.0), " 1 ", false},
137+
{float32(-1.0), " -1 ", false},
138+
{float32(0.5), " 0.5 ", false},
139+
{float32(-0.5), " -0.5 ", false},
140+
{float32(1.0) / float32(256), " 0.00390625 ", false},
141+
{float32(0), " 0 ", false},
142+
{math.Copysign(0, -1), " -0 ", false},
143+
{float64(1.0), " 1 ", false},
144+
{float64(-1.0), " -1 ", false},
145+
{float64(0.5), " 0.5 ", false},
146+
{float64(-0.5), " -0.5 ", false},
147+
{float64(0), " 0 ", false},
148+
{math.Copysign(0, -1), " -0 ", false},
149+
{"", `""`, false},
150+
{"foo", `"foo"`, false},
143151
// Newlines.
144-
{"\r\n\u2028\u2029", `"\r\n\u2028\u2029"`},
152+
{"\r\n\u2028\u2029", `"\r\n\u2028\u2029"`, false},
145153
// "\v" == "v" on IE 6 so use "\u000b" instead.
146-
{"\t\x0b", `"\t\u000b"`},
147-
{struct{ X, Y int }{1, 2}, `{"X":1,"Y":2}`},
148-
{[]any{}, "[]"},
149-
{[]any{42, "foo", nil}, `[42,"foo",null]`},
150-
{[]string{"<!--", "</script>", "-->"}, `["\u003c!--","\u003c/script\u003e","--\u003e"]`},
151-
{"<!--", `"\u003c!--"`},
152-
{"-->", `"--\u003e"`},
153-
{"<![CDATA[", `"\u003c![CDATA["`},
154-
{"]]>", `"]]\u003e"`},
155-
{"</script", `"\u003c/script"`},
156-
{"\U0001D11E", "\"\U0001D11E\""}, // or "\uD834\uDD1E"
157-
{nil, " null "},
154+
{"\t\x0b", `"\t\u000b"`, false},
155+
{struct{ X, Y int }{1, 2}, `{"X":1,"Y":2}`, false},
156+
{[]any{}, "[]", false},
157+
{[]any{42, "foo", nil}, `[42,"foo",null]`, false},
158+
{[]string{"<!--", "</script>", "-->"}, `["\u003c!--","\u003c/script\u003e","--\u003e"]`, false},
159+
{"<!--", `"\u003c!--"`, false},
160+
{"-->", `"--\u003e"`, false},
161+
{"<![CDATA[", `"\u003c![CDATA["`, false},
162+
{"]]>", `"]]\u003e"`, false},
163+
{"</script", `"\u003c/script"`, false},
164+
{"\U0001D11E", "\"\U0001D11E\"", false}, // or "\uD834\uDD1E"
165+
{nil, " null ", false},
166+
{&jsonErrType{}, " /* json: error calling MarshalJSON for type *template.jsonErrType: beep * / boop \\x3C/script blip \\x3C!-- */null ", true},
158167
}
159168

160169
for _, test := range tests {
161170
if js := jsValEscaper(test.x); js != test.js {
162171
t.Errorf("%+v: want\n\t%q\ngot\n\t%q", test.x, test.js, js)
163172
}
173+
if test.skipNest {
174+
continue
175+
}
164176
// Make sure that escaping corner cases are not broken
165177
// by nesting.
166178
a := []any{test.x}

tpl/internal/go_templates/testenv/exec.go

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package testenv
66

77
import (
88
"context"
9+
"errors"
910
"fmt"
1011
"os"
1112
"os/exec"
@@ -60,6 +61,13 @@ func tryExec() error {
6061
// may as well use the same path so that this branch can be tested without
6162
// an ios environment.
6263

64+
if !testing.Testing() {
65+
// This isn't a standard 'go test' binary, so we don't know how to
66+
// self-exec in a way that should succeed without side effects.
67+
// Just forget it.
68+
return errors.New("can't probe for exec support with a non-test executable")
69+
}
70+
6371
// We know that this is a test executable. We should be able to run it with a
6472
// no-op flag to check for overall exec support.
6573
exe, err := os.Executable()

tpl/internal/go_templates/testenv/testenv_notunix.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ import (
1717
var Sigquit = os.Kill
1818

1919
func syscallIsNotSupported(err error) bool {
20-
return errors.Is(err, fs.ErrPermission)
20+
return errors.Is(err, fs.ErrPermission) || errors.Is(err, errors.ErrUnsupported)
2121
}

tpl/internal/go_templates/testenv/testenv_test.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func TestGoToolLocation(t *testing.T) {
5454
}
5555
}
5656

57+
// Modified by Hugo.
5758
func TestHasGoBuild(t *testing.T) {
58-
// Removed by Hugo.
5959
}
6060

6161
func TestMustHaveExec(t *testing.T) {
@@ -73,7 +73,7 @@ func TestMustHaveExec(t *testing.T) {
7373
t.Errorf("expected MustHaveExec to skip on %v", runtime.GOOS)
7474
}
7575
case "ios":
76-
if b := testenv.Builder(); strings.HasSuffix(b, "-corellium") && !hasExec {
76+
if b := testenv.Builder(); isCorelliumBuilder(b) && !hasExec {
7777
// Most ios environments can't exec, but the corellium builder can.
7878
t.Errorf("expected MustHaveExec not to skip on %v", b)
7979
}
@@ -106,3 +106,23 @@ func TestCleanCmdEnvPWD(t *testing.T) {
106106
}
107107
t.Error("PWD not set in cmd.Env")
108108
}
109+
110+
func isCorelliumBuilder(builderName string) bool {
111+
// Support both the old infra's builder names and the LUCI builder names.
112+
// The former's names are ad-hoc so we could maintain this invariant on
113+
// the builder side. The latter's names are structured, and "corellium" will
114+
// appear as a "host" suffix after the GOOS and GOARCH, which always begin
115+
// with an underscore.
116+
return strings.HasSuffix(builderName, "-corellium") || strings.Contains(builderName, "_corellium")
117+
}
118+
119+
func isEmulatedBuilder(builderName string) bool {
120+
// Support both the old infra's builder names and the LUCI builder names.
121+
// The former's names are ad-hoc so we could maintain this invariant on
122+
// the builder side. The latter's names are structured, and the signifier
123+
// of emulation "emu" will appear as a "host" suffix after the GOOS and
124+
// GOARCH because it modifies the run environment in such a way that it
125+
// the target GOOS and GOARCH may not match the host. This suffix always
126+
// begins with an underscore.
127+
return strings.HasSuffix(builderName, "-emu") || strings.Contains(builderName, "_emu")
128+
}

tpl/internal/go_templates/testenv/testenv_unix.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func syscallIsNotSupported(err error) bool {
3535
}
3636
}
3737

38-
if errors.Is(err, fs.ErrPermission) {
38+
if errors.Is(err, fs.ErrPermission) || errors.Is(err, errors.ErrUnsupported) {
3939
return true
4040
}
4141

tpl/internal/go_templates/texttemplate/parse/node.go

-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ func (a *ActionNode) tree() *Tree {
284284

285285
func (a *ActionNode) Copy() Node {
286286
return a.tr.newAction(a.Pos, a.Line, a.Pipe.CopyPipe())
287-
288287
}
289288

290289
// CommandNode holds a command (a pipeline inside an evaluating action).

0 commit comments

Comments
 (0)