antpath

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package antpath matches paths against Ant-style patterns, the form Artifactory uses for permission target and repository include and exclude patterns, token scope paths, the pattern search and remote repositories' external dependency patterns: '/' separates segments, "**" matches any number of segments, '*' any run of characters within one segment and '?' exactly one character.

Role

kernel layer: Ant-style path matching that access permission targets and artifacts repository patterns share. The rest of the kernel holds values with no behaviour beyond parsing; this package holds matching behaviour, and sits in the kernel so that artifacts code can match its repository patterns without importing access. It imports only the standard library.

Inputs

  • Patterns as configured or requested: a leading '/' is ignored, and a trailing '/' means everything below, so "dir/" is "dir/**".
  • Paths relative to a repository root, '/'-separated; "" is the root.

Outputs

  • CompilePattern, which turns a pattern into a Pattern.
  • Pattern.Match, whether a pattern matches a path, and Pattern.MatchBelow, whether it could match some path below a folder, which is how a listing shows the folders that lead to permitted content, and Pattern.MatchAllBelow, whether it matches every path below a folder, which is how a list knows it may count in its store what a caller may read (#1425, #1426).

Invariants

  • Matching follows Ant semantics and is case-sensitive (decision 0006). Permission answers, repository pattern checks and searches depend on it, so every match answer stays as it is.
  • Match fills a table rather than backtracking, so a pattern with many "**" segments cannot take exponential time on a path from a request.
  • Segments are compared rune by rune, so '?' matches one character rather than one byte of a multi-byte character.

References

Status

Implemented P4 with the native permission evaluator. Moved here in P9d.

Testing

  • TestUnitPatternMatch: the examples of Ant's pattern documentation, which Artifactory's include and exclude patterns follow, and Artifactory's usual forms.
  • TestUnitPatternMatchBelow: the folders that lead to content a pattern can match.
  • TestUnitPatternMatchAllBelow: the folders below which a pattern matches every path.
  • FuzzPatternMatch, with inline seeds and no seed corpus directory: Match agrees with a direct recursive matcher, and "**" matches every path. make test runs the seeds (FUZZ_PKGS) and CI runs them in the three-OS Go test matrix; go test -fuzz=FuzzPatternMatch explores further. FuzzPatternMatchAllBelow, run the same way: a pattern that MatchAllBelow says matches every path below a folder matches each path below it the fuzzer tries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pattern

type Pattern struct {
	// contains filtered or unexported fields
}

Pattern is a compiled Ant-style path pattern: '/' separates segments, "**" matches zero or more segments, '*' any run of characters within a segment, '?' exactly one character. Matching is case-sensitive and paths are relative to the repository root.

func CompilePattern

func CompilePattern(p string) Pattern

CompilePattern compiles p. A leading '/' is ignored and a trailing '/' means everything below, as in Ant ("dir/" is "dir/**").

func (Pattern) Match

func (p Pattern) Match(path string) bool

Match reports whether the pattern matches path ("" is the repository root, which only patterns that can match zero segments match).

func (Pattern) MatchAllBelow

func (p Pattern) MatchAllBelow(folder string) bool

MatchAllBelow reports whether the pattern matches every path below folder, a path of at least one more segment ("" for every path but the root), whatever those segments hold. A list relies on it to count what lies below a folder without matching each path, so it must never be true when some path below the folder fails Match; it may be false when every path matches, which only costs that list its shortcut. It is true when the pattern has a "**", each segment before it matches the folder's segment at its place or, past the folder, is made of '*' alone, each segment after it is made of '*' alone, and the shortest path below the folder has a segment for each of those: "**", "a/**" below "a", "*/**", "**/*" and "a/" (which is "a/**").

func (Pattern) MatchBelow

func (p Pattern) MatchBelow(folder string) bool

MatchBelow reports whether the pattern could match some path below folder, so a listing can show the folders that lead to permitted content (Ant's matchPatternStart).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL