Skip to content

parser: CR (\r) is not allowed in string literals if not followed by LF (\n) #482

@Kijewski

Description

@Kijewski

The generator expects that parser ensures that string literals are valid as they are:

buf.write(format_args!("\"{}\"", s.content));

That expectation is sane, because it's in the parser's contract:

pub struct StrLit<'a> {
/// the unparsed (but validated) content
pub content: &'a str,

The parser has to reject a CR if not followed by NL: https://doc.rust-lang.org/reference/tokens.html#string-literals


Issue: https://issues.oss-fuzz.com/issues/424227903

Artifact:

data:application/octet-steam;base64,////e3sgKCIgDSAiKX19/yAg/2n/ICA=

Formatted test case:

#[test]
fn test() -> Result<(), syn::Error> {
    let input = quote! {
        #[template(ext = "", source = "{{ (\" \r \")}}")]
//                                          ^^ not followed by `\n`
        enum i {}
    };
    let output = derive_template(input, import_askama);
    let _: syn::File = syn::parse2(output)?;
    Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfuzzing errorA bug found by fuzzingparserRelated to the parser

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions