* chore(deps): consolidate dependency and security bumps Dependabot PRs applied: - #12878 qs 6.15.2 -> 6.16.0 (web/web-runtime) - #13013 alpine 3.24.1 -> 3.24.2 - #13061 actions/checkout -> v7.0.1 (missed instance in k8s.yml) - #13062 actions/setup-node -> v7.0.0 (missed instance in k8s.yml) - #13075 simple-git 3.36.0 -> 4.0.1 (security) - #13076 katex 0.16.45 -> 0.18.2+ (security) - #13077 dompurify 3.4.13 -> 3.4.16 (security) - #13079 go deps minor-and-patch group, 18 updates (opa 1.19.0 -> 1.21.1, otel 1.46 -> 1.47, bleve, govips, grpc-gateway, lico, tablewriter, logrus, gjson, x/exp, x/image, genproto, etc.) Skipped (already satisfied on master): #12513, #12624, #12625, #12633 Manual security bumps via pnpm.overrides (no dependabot PR existed): - axios -> 1.20.0 - smol-toml -> 1.9.0 - postcss -> 8.5.23 - postcss-selector-parser -> 7.1.6 - colord -> 2.9.4 - unhead -> 2.1.13 - markdown-it -> 14.3.1 - esbuild -> 0.28.1 - brace-expansion 5.0.11 -> 5.0.12 Not fixable: sprintf-js and elliptic have no patched version released upstream yet; left as-is. go build and pnpm install verified clean. * chore(deps): fix residual transitive vulns found by trivy trivy flagged duplicate/stale resolutions that survived the earlier override pass: dompurify (3.4.12 -> 3.4.16), qs (6.14.2 -> 6.16.0), and fast-uri (3.1.7 -> 3.1.8, CVE-2026-86472). Added/bumped pnpm.overrides accordingly. trivy fs scan of web/pnpm-lock.yaml now clean. * chore(deps): bump reva to bac0e1ee144ab853a81c6b02142032f102dd245a Pins github.com/owncloud/reva/v2 to bac0e1ee144ab853a81c6b02142032f102dd245a, pulling in its go-playground/locales and huandu/xstrings version bumps. Appends this PR to changelog/unreleased/bump-reva.md. go build ./... verified clean after go mod vendor resync. * fix(ci): revert unhead override, breaks web build * revert: keep k8s.yml actions/checkout and setup-node pinned
159 lines
4.8 KiB
Go
159 lines
4.8 KiB
Go
package glob
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gobwas/glob/internal/debug"
|
|
"github.com/gobwas/glob/syntax"
|
|
)
|
|
|
|
// SyntaxError is returned by [Compile] when the given pattern can not be
|
|
// parsed. Offset points at the place in the pattern the error was detected
|
|
// at, so the tooling can do things like:
|
|
//
|
|
// {a,b
|
|
// ----^ unclosed `{`
|
|
type SyntaxError struct {
|
|
// Offset is a byte offset in the pattern.
|
|
Offset int
|
|
// Reason describes the error.
|
|
Reason string
|
|
}
|
|
|
|
func (s *SyntaxError) Error() string {
|
|
return fmt.Sprintf("glob: syntax error at %d: %s", s.Offset, s.Reason)
|
|
}
|
|
|
|
// Pattern represents a compiled glob pattern.
|
|
//
|
|
// A pattern is compiled into a tree of matchers:
|
|
//
|
|
// `a` => "a"
|
|
// `a*` => ["a"·*]
|
|
// `{a*,b}` => {["a"·*]|"b"}
|
|
//
|
|
// Matching is a backtracking walk over that tree; see [Pattern.Match].
|
|
type Pattern struct {
|
|
// str is the pattern text the Pattern was compiled from; see
|
|
// [Pattern.String].
|
|
str string
|
|
|
|
// sep are the separators the Pattern was compiled with; see
|
|
// [Pattern.Separators].
|
|
sep []rune
|
|
|
|
// m is the root of the matcher tree; see [matcher].
|
|
m matcher
|
|
|
|
// state tells whether matching m needs the backtracking state, that
|
|
// is, whether it may save checkpoints; see [needsState]. A pattern
|
|
// without them is matched with a plain call chain.
|
|
state bool
|
|
|
|
// The match preconditions: every matching string is at least minLen
|
|
// bytes and ends with suffix. They fail the obvious mismatches in O(1)
|
|
// instead of a backtracking walk -- e.g. `a*a*a*b` requires the
|
|
// trailing `b`, no matter how the stars go.
|
|
//
|
|
// A precondition pays off only when it catches a mismatch earlier than
|
|
// the walk would, which is why:
|
|
//
|
|
// - there is no required prefix: the walk is left-to-right, so a
|
|
// leading literal is the first thing checked anyway, while a bad
|
|
// suffix or length is discovered last, after the whole
|
|
// backtracking exploration;
|
|
//
|
|
// - they are computed for the stateful patterns only: a stateless
|
|
// pattern is a plain call chain whose matchers perform these very
|
|
// checks themselves (e.g. suffixMatcher is a HasSuffix), so the
|
|
// precondition would only duplicate them.
|
|
minLen int
|
|
suffix string
|
|
}
|
|
|
|
// String returns the source text used to compile the pattern, the same way
|
|
// [regexp.Regexp.String] does.
|
|
//
|
|
// Note that separators are not part of String: they are given to Compile
|
|
// alongside the pattern text.
|
|
func (p *Pattern) String() string {
|
|
return p.str
|
|
}
|
|
|
|
// Separators returns the separators the pattern was compiled with, in the
|
|
// order they were given to Compile; nil when there are none.
|
|
//
|
|
// The returned slice is the very one given to Compile, sharing its backing
|
|
// array: it is not copied on the way in or out. Matching does not use it.
|
|
func (p *Pattern) Separators() []rune {
|
|
return p.sep
|
|
}
|
|
|
|
func init() {
|
|
// The matcher tree is unexported; hand its rendering to the in-module
|
|
// tooling (cmd/globtest -v) without widening the public API.
|
|
debug.Tree = func(p any) string {
|
|
return p.(*Pattern).m.String()
|
|
}
|
|
}
|
|
|
|
// Compile compiles the glob pattern. The separators, if given, are the
|
|
// characters `*` and `?` do not match (`**` does); they can not be changed
|
|
// after the compilation, see [Pattern.Separators]. A malformed pattern is
|
|
// reported with a [*SyntaxError].
|
|
//
|
|
// The pattern syntax is:
|
|
//
|
|
// pattern:
|
|
// { term }
|
|
//
|
|
// term:
|
|
// `*` matches any sequence of non-separator characters
|
|
// `**` matches any sequence of characters
|
|
// `?` matches any single non-separator character
|
|
// `[` [ `!` ] class `]`
|
|
// character class; `!` negates it
|
|
// `{` pattern-list `}`
|
|
// pattern alternatives
|
|
// c matches character c (c != `*`, `**`, `?`, `\`, `[`, `{`, `}`)
|
|
// `\` c matches character c
|
|
//
|
|
// class:
|
|
// lo `-` hi matches character c for lo <= c <= hi
|
|
// { c } matches any of the listed characters (c != `\`, `]`;
|
|
// `\` c matches c, `-` is literal here); must be non-empty
|
|
//
|
|
// pattern-list:
|
|
// pattern { `,` pattern }
|
|
// comma-separated (without spaces) patterns
|
|
func Compile(pattern string, separators ...rune) (*Pattern, error) {
|
|
return compile(pattern, separators)
|
|
}
|
|
|
|
// MustCompile is the same as Compile, except that if Compile returns error,
|
|
// this will panic.
|
|
func MustCompile(pattern string, separators ...rune) *Pattern {
|
|
g, err := Compile(pattern, separators...)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return g
|
|
}
|
|
|
|
// QuoteMeta returns a copy of the s having all glob meta characters escaped.
|
|
func QuoteMeta(s string) string {
|
|
// 2 is a pessimistic way of allocating an extra byte per each byte in s.
|
|
b := make([]byte, 2*len(s))
|
|
j := 0
|
|
// A byte loop is correct here because all meta characters are ASCII.
|
|
for i := 0; i < len(s); i++ {
|
|
if syntax.IsSpecial(s[i]) {
|
|
b[j] = '\\'
|
|
j++
|
|
}
|
|
b[j] = s[i]
|
|
j++
|
|
}
|
|
return string(b[0:j])
|
|
}
|