From d8254773a6342a791941018ffb733b4d4d30584a Mon Sep 17 00:00:00 2001 From: jzitnik-dev Date: Fri, 22 May 2026 09:20:30 +0200 Subject: [PATCH] fix: Better escaping --- src/compiler/models_impl.rs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/compiler/models_impl.rs b/src/compiler/models_impl.rs index d306c61..85234af 100644 --- a/src/compiler/models_impl.rs +++ b/src/compiler/models_impl.rs @@ -1,4 +1,5 @@ use indoc::indoc; +use serde_json; use crate::css::scope_css; @@ -57,7 +58,10 @@ impl Project { script.push_str( &template_script - .replace("{page_route}", &format!("{:?}", minify_javascript(&route_script))) + .replace( + "{page_route}", + &serde_json::to_string(&minify_javascript(&route_script)).unwrap(), + ) .replace("{content_script}", &content_script), ); } @@ -77,7 +81,7 @@ impl PageRoute { })() "# }; - template.replace("{expr}", &format!("{:?}", expr.trim())) + template.replace("{expr}", &serde_json::to_string(&expr.trim()).unwrap()) } PageRoute::Static(route) => { let template = indoc! { r#" @@ -86,7 +90,7 @@ impl PageRoute { })() "# }; - template.replace("{route}", &format!("{:?}", route)) + template.replace("{route}", &serde_json::to_string(&route).unwrap()) } PageRoute::CustomScript(script) => script.clone(), } @@ -108,7 +112,7 @@ impl Template { styleElement.textContent = {style}; document.head.appendChild(styleElement); "#, - style = format!("{:?}", s) + style = serde_json::to_string(s).unwrap() ) }); @@ -132,7 +136,8 @@ impl Template { styleElement.textContent = {style}; document.head.appendChild(styleElement); "# }, - style = &scope_css(&style, &scope_class) + style = + &serde_json::to_string(&scope_css(&style, &scope_class)).unwrap() ) } } else { @@ -161,12 +166,24 @@ impl Template { script_template .replace("{style_script}", &style_script) - .replace("{template}", &format!("{:?}", template.trim())) - .replace("{replace_selector}", &format!("{:?}", replace_selector)) - .replace("{scope_class}", &format!("{:?}", scope_class)) + .replace( + "{template}", + &serde_json::to_string(&template.trim()).unwrap(), + ) + .replace( + "{replace_selector}", + &serde_json::to_string(&replace_selector).unwrap(), + ) + .replace( + "{scope_class}", + &serde_json::to_string(&scope_class).unwrap(), + ) .replace( "{scraper}", - &format!("{:?}", minify_javascript(scraper.as_deref().unwrap_or(""))), + &serde_json::to_string(&minify_javascript( + scraper.as_deref().unwrap_or(""), + )) + .unwrap(), ) } }