Merge pull request #569 from GuillaumeGomez/old-paths

Fix invalid handling of paths starting with `::`
This commit is contained in:
Guillaume Gomez 2025-08-13 11:39:04 +02:00 committed by GitHub
commit e40da12343
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View File

@ -786,7 +786,10 @@ impl<'a> Generator<'a, '_> {
quote_into!(buf, span, { #this #generics });
continue;
}
buf.write_field(part, span);
if i != 0 || !part.is_empty() {
// Paths can start with `::`, meaning we can have an empty identifier first.
buf.write_field(part, span);
}
}
}

View File

@ -0,0 +1 @@
<EFBFBD><EFBFBD><EFBFBD>{{::s!()}}<7D> <20>t<EFBFBD>

11
testing/tests/path.rs Normal file
View File

@ -0,0 +1,11 @@
use askama::Template;
// Ensure that paths starting with `::` are supported correctly.
#[test]
fn test_path_starting_with_colon() {
#[derive(Template)]
#[template(source = r#"<EFBFBD><EFBFBD><EFBFBD>{{::std::format!("")}}<7D> <20>t<EFBFBD>"#, ext = "txt")]
struct X;
assert_eq!(X.render().unwrap(), "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>t<EFBFBD>");
}