aboutsummaryrefslogtreecommitdiffstats
path: root/askama_escape/src
diff options
context:
space:
mode:
Diffstat (limited to 'askama_escape/src')
-rw-r--r--askama_escape/src/lib.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/askama_escape/src/lib.rs b/askama_escape/src/lib.rs
index ef6c1f9..e09a32d 100644
--- a/askama_escape/src/lib.rs
+++ b/askama_escape/src/lib.rs
@@ -113,12 +113,20 @@ impl Escaper for Html {
{
let mut last = 0;
for (index, byte) in string.bytes().enumerate() {
+ const MIN_CHAR: u8 = b'"';
+ const MAX_CHAR: u8 = b'>';
+ const TABLE: [Option<&&str>; (MAX_CHAR - MIN_CHAR + 1) as usize] = {
+ let mut table = [None; (MAX_CHAR - MIN_CHAR + 1) as usize];
+ table[(b'<' - MIN_CHAR) as usize] = Some(&"&lt;");
+ table[(b'>' - MIN_CHAR) as usize] = Some(&"&gt;");
+ table[(b'&' - MIN_CHAR) as usize] = Some(&"&amp;");
+ table[(b'"' - MIN_CHAR) as usize] = Some(&"&quot;");
+ table[(b'\'' - MIN_CHAR) as usize] = Some(&"&#x27;");
+ table
+ };
+
let escaped = match byte {
- b'<' => Some(&"&lt;"),
- b'>' => Some(&"&gt;"),
- b'&' => Some(&"&amp;"),
- b'"' => Some(&"&quot;"),
- b'\'' => Some(&"&#x27;"),
+ MIN_CHAR..=MAX_CHAR => TABLE[(byte - MIN_CHAR) as usize],
_ => None,
};
if let Some(escaped) = escaped {