Skip to content

Illegal macro name emitted and illegal tokens in macros accepted #459

@Kijewski

Description

@Kijewski
    • The generator needs to escape raw identifiers in macro names: override!()r#override!().
    • The parser needs to reject illegal macro names: self!().
    • The parser needs to ensure that the inside a macro call only valid tokens are used.

Artifact:

data:application/octet-steam;base64,rf/LDGF3dHJhaXRhaXRBe3tvdmVycmlkZQwhICAMICgfICAMDCkMfX2FfWZqYI9mZmaaxGZmZmZmZgGAACxmZma//8tmZp40DA==

Formatted test case:

#[test]
fn test() -> Result<(), syn::Error> {
    let input = quote! {
        #[template(
            ext = "",
            source = "\u{c}awtraitaitA{{override\u{c}!  \u{c} (\u{1f}  \u{c}\u{c})\u{c}}}"
//                                      ^^^^^^^^               ^^^^^^
//                                      illegal identifier     illegal token
        )]
        struct f {}
    };
    let output = derive_template(input, import_askama);
    let _: syn::File = syn::parse2(output)?;
    Ok(())
}

Generated code (extract):

   override!(␟  ␌␌)
// ^^^^^^^^  ^- illegal token
// |
// illegal identifier

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions