Skip to content

Prevent crate to be used as identifier#450

Merged
GuillaumeGomez merged 5 commits intoaskama-rs:masterfrom
GuillaumeGomez:crate-identifier
May 20, 2025
Merged

Prevent crate to be used as identifier#450
GuillaumeGomez merged 5 commits intoaskama-rs:masterfrom
GuillaumeGomez:crate-identifier

Conversation

@GuillaumeGomez
Copy link
Copy Markdown
Collaborator

Fixes #449.

@GuillaumeGomez GuillaumeGomez requested a review from Kijewski May 19, 2025 20:07
Comment thread askama_parser/src/expr.rs Outdated
Comment thread testing/tests/ui/crate_identifier.rs Outdated
@Kijewski
Copy link
Copy Markdown
Member

Please add the found fuzzing failure, too:

#[test]
fn invalid_raw_identifier_crate() -> Result<(), syn::Error> {
    let input = quote! {
        #[template(
            ext = "",
            source = "{{\u{c}KK3e331<c7}}61/63m3333u7<c0.}}\u{6}\0\u{c}\u{c}{{c/crate<338<c7}}6unsafe/63a3ae\u{c}\u{c}\u{c}%et"
        )]
        struct ffffn {}
    };
    let output = derive_template(input, import_askama);
    let _: syn::File = syn::parse2(output)?;
    Ok(())
}

Comment thread testing/tests/ui/crate_identifier.rs
@GuillaumeGomez
Copy link
Copy Markdown
Collaborator Author

I think I covered all cases. :)

@Kijewski
Copy link
Copy Markdown
Member

Good idea to make this a problem of the parser, not the code generator!

I just noticed the a::b::self case, and added tests against that. If there are still problems, then the fuzzer will find them. :D

@GuillaumeGomez
Copy link
Copy Markdown
Collaborator Author

Nice catch! (and thanks for the bugfix!) Your changes look good to me. =D

Copy link
Copy Markdown
Member

@Kijewski Kijewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@GuillaumeGomez GuillaumeGomez merged commit bbd5285 into askama-rs:master May 20, 2025
39 checks passed
@GuillaumeGomez GuillaumeGomez deleted the crate-identifier branch May 20, 2025 21:27
@Kijewski Kijewski mentioned this pull request Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crate cannot be a raw identifier

2 participants