fix(init,detect): escape generated TOML and reject non-SPDX detected values - #2
Merged
Adam Poulemanos (bashandbone) merged 1 commit intoJun 28, 2026
Conversation
…values
`licet init` crashed with a TOML parse error while validating its own
generated config. Two stacked defects:
1. `render_config` interpolated detected license strings straight into TOML
basic strings (`format!("license = \"{d}\"")`) with no escaping, so any
value containing a quote, backslash, or newline produced invalid TOML.
It now builds serde structs and serializes via the `toml` crate.
2. `detect::parse_headers` accepted any text trailing the
`SPDX-License-Identifier:` tag as a license. Because the tag is matched
anywhere on a line, scanning this project's own test sources captured
junk like `MIT\nx=1\n")` from a Rust string literal. Captured values are
now kept only when they parse as a valid SPDX expression
(`spdx::validate_expression`); `LicenseRef-*` and compound expressions
still pass.
Also wrap the illustrative/test SPDX tags throughout the test suite, the
benches, the relevant `#[cfg(test)]` modules, and `docs/REUSE_Specification`
in `REUSE-IgnoreStart`/`REUSE-IgnoreEnd` so neither `licet` nor the reference
`reuse` tool mistakes example tags for real licensing. `licet init` over this
repo now detects nothing instead of inferring a bogus `GPL-3.0-or-later`
default from the spec doc's examples.
Adds regression tests for both fixes. Bumps the mise `cargo:licet` pin.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6XYwUuZ7r3qtRKVfSKcMd
Adam Poulemanos (bashandbone)
approved these changes
Jun 28, 2026
Adam Poulemanos (bashandbone)
deleted the
fix/init-toml-escaping-and-spdx-validation
branch
June 28, 2026 01:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Opened by Proxy Coder on behalf of Adam Poulemanos (@bashandbone)
Summary
licet initcrashed validating its own generated config:Root cause was two stacked defects, both fixed here, plus REUSE hygiene so the bug's trigger can't recur.
1. Unescaped TOML in
init(the crash)render_configinterpolated detected license strings straight into TOML basic strings viaformat!("license = \"{d}\"")— no escaping. Any value with a quote, backslash, or newline produced invalid TOML, whichinitthen failed to re-parse. It now buildsserdestructs and serializes through thetomlcrate, so every value is correctly quoted/escaped.2. Over-greedy SPDX detection (the junk value)
detect::parse_headersaccepted any text trailing theSPDX-License-Identifier:tag as a license. Since the tag is matched anywhere on a line, scanning this project's own test sources capturedMIT\nx=1\n")from a Rust string literal (tests/us5_reuse.rs). Captured values are now kept only when they parse as a valid SPDX expression (spdx::validate_expression);LicenseRef-*and compound expressions still pass.3. REUSE-Ignore hygiene
The repo has no REUSE infrastructure of its own, so every SPDX tag the tooling sees is example/test data — and the example headers in
docs/REUSE_Specification_v3.3.mdwere being inferred as a bogusGPL-3.0-or-laterdefault. Wrapped the illustrative/test tags across the test suite, benches, the relevant#[cfg(test)]modules, and the spec doc inREUSE-IgnoreStart/REUSE-IgnoreEnd.src/detect/mod.rsis intentionally left unwrapped: its test module sits past the 8 KB headlicetscans (so it's never mis-detected), and its fixtures interleave unbalanced ignore markers that an outer wrapper can't cleanly balance for the referencereusetool.Verification
licet initover this repo: exit 0, detects nothing (was: TOML parse crash, then bogusGPL-3.0-or-later).MIT);initoutput is valid TOML under adversarial input; ordinary config round-trips.cargo test --all-targets,cargo fmt --all --check, andcargo clippy --all-targets -- -D warningsall pass.Also bumps the mise
cargo:licetpin (0.1.4→0.2.1).🤖 Generated with Claude Code
Co-Authored-By: bashandbone 89049923+bashandbone@users.noreply.github.com
On-Behalf-Of: Adam Poulemanos (@bashandbone) (via knitli-proxy-coder[bot])