fix: Better escaping
This commit is contained in:
@@ -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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user