Skip to content

Commit

Permalink
add html attribute escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
Pitasi committed Sep 9, 2023
1 parent fd360bb commit 31f3c80
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions rscx-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ proc-macro = true

[dependencies]
convert_case = "0.6.0"
html-escape = "0.2.13"
proc-macro2 = "1.0.66"
proc-macro2-diagnostics = "0.10.1"
quote = "1.0.33"
Expand Down
12 changes: 10 additions & 2 deletions rscx-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ fn walk_nodes<'a>(empty_elements: &HashSet<&str>, nodes: &'a Vec<Node>) -> WalkN
// If the nodes parent is an attribute we prefix with whitespace
out.static_format.push(' ');
out.static_format.push_str("{}");
out.values.push(block.to_token_stream());
out.values.push(quote! {{
::rscx::html_escape::encode_double_quoted_attribute(
(#block).as_str()
)
}});
}
NodeAttribute::Attribute(attribute) => {
let key = match attribute.key.to_string().as_str() {
Expand All @@ -155,7 +159,11 @@ fn walk_nodes<'a>(empty_elements: &HashSet<&str>, nodes: &'a Vec<Node>) -> WalkN
out.static_format.push_str(&format!(" {}", key));
if let Some(value) = attribute.value() {
out.static_format.push_str(r#"="{}""#);
out.values.push(value.to_token_stream());
out.values.push(quote! {
::rscx::html_escape::encode_unquoted_attribute(
&format!("{}", #value)
)
});
}
}
}
Expand Down
1 change: 1 addition & 0 deletions rscx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ readme = "../README.md"

[dependencies]
axum = { version = "0.6.20", features = ["macros"], optional = true }
html-escape = "0.2.13"
rscx-macros = { workspace = true }
tokio = { version = "1.32.0", features = ["full"] }
tokio-util = { version = "0.7.8", features = ["rt"], optional = true }
Expand Down
2 changes: 2 additions & 0 deletions rscx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub use rscx_macros::*;

pub extern crate typed_builder;

pub extern crate html_escape;

pub trait CollectFragment<I>
where
I: Iterator,
Expand Down

0 comments on commit 31f3c80

Please sign in to comment.