aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/escaping.rs
diff options
context:
space:
mode:
authorLibravatar Benjamin Li <bli@linsang.com>2018-10-24 16:46:20 -0400
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-10-25 21:41:40 +0200
commit7062aabbcbb98bdeacda94071111f0fcc13a918d (patch)
treede1c6af82e83359e843797b916ec04a3c2aa1c04 /askama_shared/src/escaping.rs
parent5be6479f2c4fc68b9a62f9359dda673be76ada15 (diff)
downloadaskama-7062aabbcbb98bdeacda94071111f0fcc13a918d.tar.gz
askama-7062aabbcbb98bdeacda94071111f0fcc13a918d.tar.bz2
askama-7062aabbcbb98bdeacda94071111f0fcc13a918d.zip
Fix off-by-one error with HTML escaping
If the second-to-last character of a string should be escaped, but not the last, the last character was not being included in the result.
Diffstat (limited to '')
-rw-r--r--askama_shared/src/escaping.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/askama_shared/src/escaping.rs b/askama_shared/src/escaping.rs
index e22e0ce..93545fd 100644
--- a/askama_shared/src/escaping.rs
+++ b/askama_shared/src/escaping.rs
@@ -96,7 +96,7 @@ pub fn escape(s: String) -> String {
_ => panic!("incorrect indexing"),
}
}
- if start < bytes.len() - 1 {
+ if start < bytes.len() {
res.extend(&bytes[start..]);
}
@@ -112,5 +112,6 @@ mod tests {
assert_eq!(escape("<&>".to_string()), "&lt;&amp;&gt;");
assert_eq!(escape("bla&".to_string()), "bla&amp;");
assert_eq!(escape("<foo".to_string()), "&lt;foo");
+ assert_eq!(escape("bla&h".to_string()), "bla&amp;h");
}
}