Skip to content

Commit

Permalink
Fix off-by-one error with HTML escaping
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benjunmun authored and djc committed Oct 25, 2018
1 parent 5be6479 commit 7062aab
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion askama_shared/src/escaping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..]);
}

Expand All @@ -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");
}
}

0 comments on commit 7062aab

Please sign in to comment.