mirror of
https://github.com/cloudflare/cloudflared.git
synced 2026-08-07 07:14:57 +00:00
Bump golang.org/x/net from v0.40.0 to v0.53.0
Check / check (1.22.x, macos-latest) (push) Has been cancelled
Check / check (1.22.x, ubuntu-latest) (push) Has been cancelled
Check / check (1.22.x, windows-latest) (push) Has been cancelled
Semgrep config / semgrep/ci (push) Has been cancelled
Check / check (1.22.x, macos-latest) (push) Has been cancelled
Check / check (1.22.x, ubuntu-latest) (push) Has been cancelled
Check / check (1.22.x, windows-latest) (push) Has been cancelled
Semgrep config / semgrep/ci (push) Has been cancelled
This commit is contained in:
committed by
Miguel da Costa Martins Marcelino
parent
4d8df2b2c0
commit
ae3799a098
+101
-33
@@ -20,10 +20,11 @@
|
||||
package modfile
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
@@ -44,6 +45,7 @@ type File struct {
|
||||
Replace []*Replace
|
||||
Retract []*Retract
|
||||
Tool []*Tool
|
||||
Ignore []*Ignore
|
||||
|
||||
Syntax *FileSyntax
|
||||
}
|
||||
@@ -100,6 +102,12 @@ type Tool struct {
|
||||
Syntax *Line
|
||||
}
|
||||
|
||||
// An Ignore is a single ignore statement.
|
||||
type Ignore struct {
|
||||
Path string
|
||||
Syntax *Line
|
||||
}
|
||||
|
||||
// A VersionInterval represents a range of versions with upper and lower bounds.
|
||||
// Intervals are closed: both bounds are included. When Low is equal to High,
|
||||
// the interval may refer to a single version ('v1.2.3') or an interval
|
||||
@@ -304,7 +312,7 @@ func parseToFile(file string, data []byte, fix VersionFixer, strict bool) (parse
|
||||
})
|
||||
}
|
||||
continue
|
||||
case "module", "godebug", "require", "exclude", "replace", "retract", "tool":
|
||||
case "module", "godebug", "require", "exclude", "replace", "retract", "tool", "ignore":
|
||||
for _, l := range x.Line {
|
||||
f.add(&errs, x, l, x.Token[0], l.Token, fix, strict)
|
||||
}
|
||||
@@ -337,7 +345,7 @@ func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, a
|
||||
// and simply ignore those statements.
|
||||
if !strict {
|
||||
switch verb {
|
||||
case "go", "module", "retract", "require":
|
||||
case "go", "module", "retract", "require", "ignore":
|
||||
// want these even for dependency go.mods
|
||||
default:
|
||||
return
|
||||
@@ -360,7 +368,7 @@ func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, a
|
||||
Err: err,
|
||||
})
|
||||
}
|
||||
errorf := func(format string, args ...interface{}) {
|
||||
errorf := func(format string, args ...any) {
|
||||
wrapError(fmt.Errorf(format, args...))
|
||||
}
|
||||
|
||||
@@ -531,6 +539,21 @@ func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, a
|
||||
Path: s,
|
||||
Syntax: line,
|
||||
})
|
||||
|
||||
case "ignore":
|
||||
if len(args) != 1 {
|
||||
errorf("ignore directive expects exactly one argument")
|
||||
return
|
||||
}
|
||||
s, err := parseString(&args[0])
|
||||
if err != nil {
|
||||
errorf("invalid quoted string: %v", err)
|
||||
return
|
||||
}
|
||||
f.Ignore = append(f.Ignore, &Ignore{
|
||||
Path: s,
|
||||
Syntax: line,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,7 +574,7 @@ func parseReplace(filename string, line *Line, verb string, args []string, fix V
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
errorf := func(format string, args ...interface{}) *Error {
|
||||
errorf := func(format string, args ...any) *Error {
|
||||
return wrapError(fmt.Errorf(format, args...))
|
||||
}
|
||||
|
||||
@@ -662,7 +685,7 @@ func (f *WorkFile) add(errs *ErrorList, line *Line, verb string, args []string,
|
||||
Err: err,
|
||||
})
|
||||
}
|
||||
errorf := func(format string, args ...interface{}) {
|
||||
errorf := func(format string, args ...any) {
|
||||
wrapError(fmt.Errorf(format, args...))
|
||||
}
|
||||
|
||||
@@ -1571,7 +1594,7 @@ func (f *File) AddRetract(vi VersionInterval, rationale string) error {
|
||||
r.Syntax = f.Syntax.addLine(nil, "retract", "[", AutoQuote(vi.Low), ",", AutoQuote(vi.High), "]")
|
||||
}
|
||||
if rationale != "" {
|
||||
for _, line := range strings.Split(rationale, "\n") {
|
||||
for line := range strings.SplitSeq(rationale, "\n") {
|
||||
com := Comment{Token: "// " + line}
|
||||
r.Syntax.Comment().Before = append(r.Syntax.Comment().Before, com)
|
||||
}
|
||||
@@ -1619,6 +1642,36 @@ func (f *File) DropTool(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddIgnore adds a new ignore directive with the given path.
|
||||
// It does nothing if the ignore line already exists.
|
||||
func (f *File) AddIgnore(path string) error {
|
||||
for _, t := range f.Ignore {
|
||||
if t.Path == path {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
f.Ignore = append(f.Ignore, &Ignore{
|
||||
Path: path,
|
||||
Syntax: f.Syntax.addLine(nil, "ignore", path),
|
||||
})
|
||||
|
||||
f.SortBlocks()
|
||||
return nil
|
||||
}
|
||||
|
||||
// DropIgnore removes a ignore directive with the given path.
|
||||
// It does nothing if no such ignore directive exists.
|
||||
func (f *File) DropIgnore(path string) error {
|
||||
for _, t := range f.Ignore {
|
||||
if t.Path == path {
|
||||
t.Syntax.markRemoved()
|
||||
*t = Ignore{}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *File) SortBlocks() {
|
||||
f.removeDups() // otherwise sorting is unsafe
|
||||
|
||||
@@ -1633,15 +1686,13 @@ func (f *File) SortBlocks() {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
less := lineLess
|
||||
less := compareLine
|
||||
if block.Token[0] == "exclude" && useSemanticSortForExclude {
|
||||
less = lineExcludeLess
|
||||
less = compareLineExclude
|
||||
} else if block.Token[0] == "retract" {
|
||||
less = lineRetractLess
|
||||
less = compareLineRetract
|
||||
}
|
||||
sort.SliceStable(block.Line, func(i, j int) bool {
|
||||
return less(block.Line[i], block.Line[j])
|
||||
})
|
||||
slices.SortStableFunc(block.Line, less)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1657,10 +1708,10 @@ func (f *File) SortBlocks() {
|
||||
// retract directives are not de-duplicated since comments are
|
||||
// meaningful, and versions may be retracted multiple times.
|
||||
func (f *File) removeDups() {
|
||||
removeDups(f.Syntax, &f.Exclude, &f.Replace, &f.Tool)
|
||||
removeDups(f.Syntax, &f.Exclude, &f.Replace, &f.Tool, &f.Ignore)
|
||||
}
|
||||
|
||||
func removeDups(syntax *FileSyntax, exclude *[]*Exclude, replace *[]*Replace, tool *[]*Tool) {
|
||||
func removeDups(syntax *FileSyntax, exclude *[]*Exclude, replace *[]*Replace, tool *[]*Tool, ignore *[]*Ignore) {
|
||||
kill := make(map[*Line]bool)
|
||||
|
||||
// Remove duplicate excludes.
|
||||
@@ -1719,6 +1770,24 @@ func removeDups(syntax *FileSyntax, exclude *[]*Exclude, replace *[]*Replace, to
|
||||
*tool = newTool
|
||||
}
|
||||
|
||||
if ignore != nil {
|
||||
haveIgnore := make(map[string]bool)
|
||||
for _, i := range *ignore {
|
||||
if haveIgnore[i.Path] {
|
||||
kill[i.Syntax] = true
|
||||
continue
|
||||
}
|
||||
haveIgnore[i.Path] = true
|
||||
}
|
||||
var newIgnore []*Ignore
|
||||
for _, i := range *ignore {
|
||||
if !kill[i.Syntax] {
|
||||
newIgnore = append(newIgnore, i)
|
||||
}
|
||||
}
|
||||
*ignore = newIgnore
|
||||
}
|
||||
|
||||
// Duplicate require and retract directives are not removed.
|
||||
|
||||
// Drop killed statements from the syntax tree.
|
||||
@@ -1746,39 +1815,38 @@ func removeDups(syntax *FileSyntax, exclude *[]*Exclude, replace *[]*Replace, to
|
||||
syntax.Stmt = stmts
|
||||
}
|
||||
|
||||
// lineLess returns whether li should be sorted before lj. It sorts
|
||||
// lexicographically without assigning any special meaning to tokens.
|
||||
func lineLess(li, lj *Line) bool {
|
||||
// compareLine compares li and lj. It sorts lexicographically without assigning
|
||||
// any special meaning to tokens.
|
||||
func compareLine(li, lj *Line) int {
|
||||
for k := 0; k < len(li.Token) && k < len(lj.Token); k++ {
|
||||
if li.Token[k] != lj.Token[k] {
|
||||
return li.Token[k] < lj.Token[k]
|
||||
return cmp.Compare(li.Token[k], lj.Token[k])
|
||||
}
|
||||
}
|
||||
return len(li.Token) < len(lj.Token)
|
||||
return cmp.Compare(len(li.Token), len(lj.Token))
|
||||
}
|
||||
|
||||
// lineExcludeLess reports whether li should be sorted before lj for lines in
|
||||
// an "exclude" block.
|
||||
func lineExcludeLess(li, lj *Line) bool {
|
||||
// compareLineExclude compares li and lj for lines in an "exclude" block.
|
||||
func compareLineExclude(li, lj *Line) int {
|
||||
if len(li.Token) != 2 || len(lj.Token) != 2 {
|
||||
// Not a known exclude specification.
|
||||
// Fall back to sorting lexicographically.
|
||||
return lineLess(li, lj)
|
||||
return compareLine(li, lj)
|
||||
}
|
||||
// An exclude specification has two tokens: ModulePath and Version.
|
||||
// Compare module path by string order and version by semver rules.
|
||||
if pi, pj := li.Token[0], lj.Token[0]; pi != pj {
|
||||
return pi < pj
|
||||
return cmp.Compare(pi, pj)
|
||||
}
|
||||
return semver.Compare(li.Token[1], lj.Token[1]) < 0
|
||||
return semver.Compare(li.Token[1], lj.Token[1])
|
||||
}
|
||||
|
||||
// lineRetractLess returns whether li should be sorted before lj for lines in
|
||||
// a "retract" block. It treats each line as a version interval. Single versions
|
||||
// are compared as if they were intervals with the same low and high version.
|
||||
// compareLineRetract compares li and lj for lines in a "retract" block.
|
||||
// It treats each line as a version interval. Single versions are compared as
|
||||
// if they were intervals with the same low and high version.
|
||||
// Intervals are sorted in descending order, first by low version, then by
|
||||
// high version, using semver.Compare.
|
||||
func lineRetractLess(li, lj *Line) bool {
|
||||
// high version, using [semver.Compare].
|
||||
func compareLineRetract(li, lj *Line) int {
|
||||
interval := func(l *Line) VersionInterval {
|
||||
if len(l.Token) == 1 {
|
||||
return VersionInterval{Low: l.Token[0], High: l.Token[0]}
|
||||
@@ -1792,9 +1860,9 @@ func lineRetractLess(li, lj *Line) bool {
|
||||
vii := interval(li)
|
||||
vij := interval(lj)
|
||||
if cmp := semver.Compare(vii.Low, vij.Low); cmp != 0 {
|
||||
return cmp > 0
|
||||
return -cmp
|
||||
}
|
||||
return semver.Compare(vii.High, vij.High) > 0
|
||||
return -semver.Compare(vii.High, vij.High)
|
||||
}
|
||||
|
||||
// checkCanonicalVersion returns a non-nil error if vers is not a canonical
|
||||
|
||||
Reference in New Issue
Block a user