Documentation
¶
Overview ¶
Package licenseexpr is the one place Bomly parses SPDX license expressions.
License strings are untrusted input: they arrive from lockfiles a repository commits and from registry APIs, and nothing checks their shape before they reach a parser. The SPDX expression parser Bomly uses panics on some of them -- "(((" dereferences a nil operator -- which would abort a scan rather than report an unparseable license.
Every entry point here recovers from that and reports the value as one it could not parse, which is what an unparseable license is. Callers must not reach for github.com/github/go-spdx directly; TestNoDirectSPDXExpressionUse fails when a new call site bypasses this package.
Index ¶
- func Compose(values []string) string
- func Extract(expression string) (licenses []string, err error)
- func Identifier(value string) (string, bool)
- func Satisfies(expression string, allowed []string) (ok bool, err error)
- func Valid(expression string) bool
- func ValidateAll(values []string) (valid bool, invalid []string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compose ¶
Compose joins several license expressions into one conjunctive expression. A package declaring several licenses is bound by all of them, so they join with AND, and a compound member is parenthesized to keep its own operators from binding across the join.
Callers must validate the members first: composing free text produces an expression that does not parse.
func Extract ¶
Extract returns the individual license identifiers an expression uses. An unparseable expression yields nothing.
func Identifier ¶
Identifier returns the canonical spelling of a value that is exactly one entry in the SPDX license list, and reports whether it is one.
Compound expressions are rejected: an operator ("MIT OR Apache-2.0", "GPL-2.0-only+") is an expression, not a list entry, and the two are not interchangeable in formats that hold identifiers and expressions in separate fields. Deprecated identifiers still resolve -- they remain list members.
func Satisfies ¶
Satisfies reports whether an expression is satisfied by an allowed set. An unparseable expression satisfies nothing and returns the parser's error, or false with no error when the parser could not run at all.
func Valid ¶
Valid reports whether a value parses as an SPDX license expression. Unparseable values -- free text such as "non-standard", or malformed grouping -- report false rather than failing the caller.
func ValidateAll ¶
ValidateAll reports whether every value parses as an SPDX license expression, returning the values that do not.
Types ¶
This section is empty.