Skip to content

Commit

Permalink
Make json_encode filter "safe"
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Sep 19, 2024
1 parent be4f185 commit 2c30204
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/web/page/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ pub mod filters {
Ok(value.split(pat).next())
}

pub fn json_encode<T: ?Sized + serde::Serialize>(value: &T) -> rinja::Result<String> {
Ok(serde_json::to_string(value).expect("`encode_json` failed"))
pub fn json_encode<T: ?Sized + serde::Serialize>(value: &T) -> rinja::Result<Safe<String>> {
Ok(Safe(
serde_json::to_string(value).expect("`encode_json` failed"),
))
}

pub fn rest_menu_url(current_target: &str, inner_path: &str) -> rinja::Result<String> {
Expand Down
4 changes: 2 additions & 2 deletions templates/rustdoc/topbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
{# the only text that needs escaping in a <script> is `</`, none of the
values below can include that sequence #}
{
"name": {{ metadata.name|json_encode|safe }},
"version": {{ metadata.version|json_encode|safe }}
"name": {{ metadata.name|json_encode }},
"version": {{ metadata.version|json_encode }}
}
</script>
{%- if krate is defined -%}
Expand Down

0 comments on commit 2c30204

Please sign in to comment.