Skip to content

Commit

Permalink
Go 1.21 Upgrade
Browse files Browse the repository at this point in the history
Fixes #11351
  • Loading branch information
bep committed Aug 23, 2023
1 parent 111f02d commit 24b1be4
Show file tree
Hide file tree
Showing 26 changed files with 438 additions and 108 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parameters:
defaults: &defaults
resource_class: large
docker:
- image: bepsays/ci-hugoreleaser:1.22000.20100
- image: bepsays/ci-hugoreleaser:1.22100.20000
environment: &buildenv
GOMODCACHE: /root/project/gomodcache
version: 2
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
environment:
<<: [*buildenv]
docker:
- image: bepsays/ci-hugoreleaser-linux-arm64:1.22000.20100
- image: bepsays/ci-hugoreleaser-linux-arm64:1.22100.20000
steps:
- *restore-cache
- &attach-workspace
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-dart-sass-v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.20.x]
go-version: [1.21.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.19.x,1.20.x]
go-version: [1.20.x,1.21.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
9 changes: 7 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,13 @@ func testSetupFunc() func(env *testscript.Env) error {
keyVals = append(keyVals, "SOURCE", sourceDir)

goVersion := runtime.Version()
// Strip all but the major and minor version.
goVersion = regexp.MustCompile(`^go(\d+\.\d+)`).FindStringSubmatch(goVersion)[1]

goVersion = strings.TrimPrefix(goVersion, "go")
if !strings.HasSuffix(goVersion, ".0") {
// Strip patch version.
goVersion = goVersion[:strings.LastIndex(goVersion, ".")]
}

keyVals = append(keyVals, "GOVERSION", goVersion)
envhelpers.SetEnvVars(&env.Vars, keyVals...)

Expand Down
2 changes: 1 addition & 1 deletion scripts/fork_go_templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func main() {
// The current is built with de4748c47c67392a57f250714509f590f68ad395 HEAD, tag: go1.20.
// The current is built with c19c4c566c HEAD, tag: go1.21.0.
fmt.Println("Forking ...")
defer fmt.Println("Done ...")

Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ parts:
go:
plugin: nil
stage-snaps:
- go/1.19/stable
- go/1.21/stable
prime:
- bin/go
- pkg/tool
Expand Down
2 changes: 2 additions & 0 deletions tpl/internal/go_templates/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const KnownEnv = `
GOARM
GOBIN
GOCACHE
GOCACHEPROG
GOENV
GOEXE
GOEXPERIMENT
Expand All @@ -59,6 +60,7 @@ const KnownEnv = `
GOROOT
GOSUMDB
GOTMPDIR
GOTOOLCHAIN
GOTOOLDIR
GOVCS
GOWASM
Expand Down
12 changes: 12 additions & 0 deletions tpl/internal/go_templates/htmltemplate/attr_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tpl/internal/go_templates/htmltemplate/delim_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tpl/internal/go_templates/htmltemplate/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
/*
Package template (html/template) implements data-driven templates for
generating HTML output safe against code injection. It provides the
same interface as package text/template and should be used instead of
text/template whenever the output is HTML.
same interface as [text/template] and should be used instead of
[text/template] whenever the output is HTML.
The documentation here focuses on the security features of the package.
For information about how to program the templates themselves, see the
documentation for text/template.
documentation for [text/template].
# Introduction
This package wraps package text/template so you can share its template API
This package wraps [text/template] so you can share its template API
to parse and execute HTML templates safely.
tmpl, err := template.New("name").Parse(...)
Expand Down
11 changes: 11 additions & 0 deletions tpl/internal/go_templates/htmltemplate/element_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions tpl/internal/go_templates/htmltemplate/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,13 @@ const (
// disallowed. Avoid using "html" and "urlquery" entirely in new templates.
ErrPredefinedEscaper

// errJSTmplLit: "... appears in a JS template literal"
// ErrJSTemplate: "... appears in a JS template literal"
// Example:
// <script>var tmpl = `{{.Interp}`</script>
// <script>var tmpl = `{{.Interp}}`</script>
// Discussion:
// Package html/template does not support actions inside of JS template
// literals.
//
// TODO(rolandshoemaker): we cannot add this as an exported error in a minor
// release, since it is backwards incompatible with the other minor
// releases. As such we need to leave it unexported, and then we'll add it
// in the next major release.
errJSTmplLit
ErrJSTemplate
)

func (e *Error) Error() string {
Expand Down
10 changes: 7 additions & 3 deletions tpl/internal/go_templates/htmltemplate/escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"bytes"
"fmt"
"html"

//"internal/godebug"
"io"

template "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate"
Expand Down Expand Up @@ -161,6 +163,7 @@ func (e *escaper) escape(c context, n parse.Node) context {
panic("escaping " + n.String() + " is unimplemented")
}

// Modified by Hugo.
// var debugAllowActionJSTmpl = godebug.New("jstmpllitinterp")

// escapeAction escapes an action template node.
Expand Down Expand Up @@ -227,12 +230,13 @@ func (e *escaper) escapeAction(c context, n *parse.ActionNode) context {
case stateJSDqStr, stateJSSqStr:
s = append(s, "_html_template_jsstrescaper")
case stateJSBqStr:
if SecurityAllowActionJSTmpl.Load() { // .Value() == "1" {
if SecurityAllowActionJSTmpl.Load() {
//debugAllowActionJSTmpl.IncNonDefault()
s = append(s, "_html_template_jsstrescaper")
} else {
return context{
state: stateError,
err: errorf(errJSTmplLit, n, n.Line, "%s appears in a JS template literal", n),
err: errorf(ErrJSTemplate, n, n.Line, "%s appears in a JS template literal", n),
}
}
case stateJSRegexp:
Expand Down Expand Up @@ -756,7 +760,7 @@ func (e *escaper) escapeText(c context, n *parse.TextNode) context {
} else if isComment(c.state) && c.delim == delimNone {
switch c.state {
case stateJSBlockCmt:
// https://es5.github.com/#x7.4:
// https://es5.github.io/#x7.4:
// "Comments behave like white space and are
// discarded except that, if a MultiLineComment
// contains a line terminator character, then
Expand Down
2 changes: 1 addition & 1 deletion tpl/internal/go_templates/htmltemplate/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ func TestJSEscaping(t *testing.T) {
{`'foo`, `\'foo`},
{`Go "jump" \`, `Go \"jump\" \\`},
{`Yukihiro says "今日は世界"`, `Yukihiro says \"今日は世界\"`},
{"unprintable \uFDFF", `unprintable \uFDFF`},
{"unprintable \uFFFE", `unprintable \uFFFE`},
{`<html>`, `\u003Chtml\u003E`},
{`no = in attributes`, `no \u003D in attributes`},
{`&#x27; does not become HTML entity`, `\u0026#x27; does not become HTML entity`},
Expand Down
2 changes: 1 addition & 1 deletion tpl/internal/go_templates/htmltemplate/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func tLineCmt(c context, s []byte) (context, int) {
return c, len(s)
}
c.state = endState
// Per section 7.4 of EcmaScript 5 : https://es5.github.com/#x7.4
// Per section 7.4 of EcmaScript 5 : https://es5.github.io/#x7.4
// "However, the LineTerminator at the end of the line is not
// considered to be part of the single-line comment; it is
// recognized separately by the lexical grammar and becomes part
Expand Down
10 changes: 10 additions & 0 deletions tpl/internal/go_templates/htmltemplate/urlpart_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24b1be4

Please sign in to comment.