-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use trait to avoid escaping numbers and bools at runtime
- Loading branch information
Showing
5 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::borrow::Cow; | ||
|
||
use html_escape::encode_unquoted_attribute; | ||
|
||
pub trait EscapeAttribute { | ||
fn escape_attribute(&self) -> Cow<str>; | ||
} | ||
|
||
impl EscapeAttribute for str { | ||
fn escape_attribute(&self) -> Cow<str> { | ||
encode_unquoted_attribute(self) | ||
} | ||
} | ||
|
||
impl EscapeAttribute for String { | ||
fn escape_attribute(&self) -> Cow<str> { | ||
encode_unquoted_attribute(self) | ||
} | ||
} | ||
|
||
macro_rules! impl_escape_attribute_literal { | ||
($($t:ty),*) => { | ||
$( | ||
impl EscapeAttribute for $t { | ||
fn escape_attribute(&self) -> Cow<str> { | ||
Cow::Owned(self.to_string()) | ||
} | ||
} | ||
)* | ||
}; | ||
} | ||
|
||
impl_escape_attribute_literal!( | ||
u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f32, f64, bool | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
pub mod attributes; | ||
pub use attributes::*; | ||
|
||
#[cfg(feature = "axum")] | ||
pub mod axum; | ||
pub mod context; | ||
|