Enforce the supported Liquid subset.

This commit is contained in:
2026-07-21 20:21:35 +02:00
parent 557497d4c2
commit 3ac7a8bfc4
6 changed files with 350 additions and 101 deletions

View File

@@ -11,8 +11,8 @@ pub use generation::{
write_generated_bytes, write_generated_file,
};
pub use markdown::render_markdown_to_html;
pub(crate) use page_renderer::render_liquid_template_with_host;
pub use page_renderer::{RenderError, render_liquid_template};
pub(crate) use page_renderer::{render_liquid_template_with_host, validate_liquid_template_syntax};
pub(crate) use routes::{PostLanguageVariant, blog_page_title, select_post_language_variant};
pub use routes::{
RenderedPage, build_canonical_post_path, render_starter_list_page,

View File

@@ -56,10 +56,7 @@ pub(crate) fn render_liquid_template_with_host<T: Serialize>(
compiled_partials.add(format!("{name}.liquid"), content.clone());
}
let parser = ParserBuilder::with_stdlib()
.filter(I18n)
.filter(Markdown { host })
.filter(Slugify)
let parser = liquid_parser_builder(host)
.partials(compiled_partials)
.build()?;
let template = parser.parse(template_source)?;
@@ -67,6 +64,23 @@ pub(crate) fn render_liquid_template_with_host<T: Serialize>(
Ok(template.render(&globals)?)
}
pub(crate) fn validate_liquid_template_syntax(template_source: &str) -> Result<(), String> {
let parser = liquid_parser_builder(Arc::new(UnavailableHost))
.build()
.map_err(|error| error.to_string())?;
parser
.parse(template_source)
.map(|_| ())
.map_err(|error| error.to_string())
}
fn liquid_parser_builder(host: Arc<dyn HostApi>) -> ParserBuilder {
ParserBuilder::with_stdlib()
.filter(I18n)
.filter(Markdown { host })
.filter(Slugify)
}
#[derive(Clone, ParseFilter, FilterReflection)]
#[filter(
name = "slugify",