Repository navigation
codegen: escape companion include! names, and reject a path in release builds too - #718
Merged
iainmcgin merged 3 commits intoOct 20, 2026
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
…escaping test An empty name, `.` and `..` contain no separator, so they passed the check and produced an include! of a directory. apply_companions now panics for them as well, before any output is changed. apply_companions_escapes_name_in_include compared the parsed literal's value with the name. A raw newline, tab or bidi control parses to the same value as its escape, so only the quote pinned the escaping. The test now also compares the appended text with the escaped literal, and the name gains a carriage return, which does not lex unescaped.
iainmcgin
reviewed
Oct 16, 2026
iainmcgin
left a comment
Collaborator
There was a problem hiding this comment.
[claude code] Pushed one maintainer commit on top of yours (11235ce); the escaping and the release-build check are as you wrote them.
- An empty name,
.and..contain no separator, so they passed the check and produced aninclude!of a directory.apply_companionsnow panics for them too, before any output is changed; the rustdoc,# Panicsand the fragment say so. apply_companions_escapes_name_in_includecompared the parsed literal with the name. A raw newline, tab or bidi control parses to the same value as its escape, so only the quote pinned the escaping. The test now also compares the text appended to the stitcher with the escaped literal, and the name gains a carriage return, which does not lex unescaped.- New test
apply_companions_rejects_names_that_are_not_files: a good companion first, then each of the three names; it checks the panic message and that no output changed.
cargo test -p buffa-codegen passes on this head (938 passed), and the apply_companions tests pass with --release.
iainmcgin
approved these changes
Oct 20, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #708.
apply_companionswrote each companion name into the stitcher asinclude!("<name>")unescaped, and checked the name only with adebug_assert!, which a release build of a downstream generator skips. A name with a"then gave a stitcher that was not valid Rust or named a different file, and the error appeared in the consumer's crate.The line is now
include!({name:?});, the escaped literalgenerate_module_treewrites. The check is anassert!in every build: a name must not contain/or\, and must not be empty,.or... A"or a newline in a name is escaped now, where thedebug_assert!rejected it. Every name is checked beforefilesis changed. The issue offered anassert!or atry_apply_companionsthat returns aCodeGenError; this is theassert!, so the signature is unchanged.A generator that passed a name with a separator from a release build now panics; switch to a bare name such as
<stem>.__myplugin.rs.