a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
31 lines
1.0 KiB
Go
31 lines
1.0 KiB
Go
package hooks
|
|
|
|
import "regexp"
|
|
|
|
// GrepPatternClass classifies a Grep pattern for the symbol-redirect probe.
|
|
type GrepPatternClass int
|
|
|
|
const (
|
|
// GrepPatternSkip means the pattern is not symbol-shaped; don't probe.
|
|
GrepPatternSkip GrepPatternClass = iota
|
|
// GrepPatternSymbol means the pattern looks like a bare identifier; probe search_symbols.
|
|
GrepPatternSymbol
|
|
)
|
|
|
|
// symbolShaped matches a single identifier-shaped token. Dots and slashes are
|
|
// permitted so qualified names like "pkg.Handler" or "pkg/Type" still qualify.
|
|
var symbolShaped = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_./]*$`)
|
|
|
|
// classifyGrepPattern decides whether a pattern should trigger the
|
|
// search_symbols probe. Non-symbol patterns (regex metachars, quoted strings,
|
|
// numeric literals, multi-word prose, too short) fall through to vanilla Grep.
|
|
func classifyGrepPattern(pattern string) GrepPatternClass {
|
|
if len(pattern) <= 2 {
|
|
return GrepPatternSkip
|
|
}
|
|
if !symbolShaped.MatchString(pattern) {
|
|
return GrepPatternSkip
|
|
}
|
|
return GrepPatternSymbol
|
|
}
|