From 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:39 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/askama_escape/.cargo-checksum.json | 2 +- vendor/askama_escape/Cargo.toml | 5 ++- vendor/askama_escape/src/lib.rs | 65 ++++++++++++++++++++++++++++--- 3 files changed, 64 insertions(+), 8 deletions(-) (limited to 'vendor/askama_escape') diff --git a/vendor/askama_escape/.cargo-checksum.json b/vendor/askama_escape/.cargo-checksum.json index 2162b0a44..b4c6a0e72 100644 --- a/vendor/askama_escape/.cargo-checksum.json +++ b/vendor/askama_escape/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"b85826fa84eb43ef7150d99130476675ee3cbdd4fce78da95cb53924f4ff954e","LICENSE-APACHE":"87cb0d734c723c083e51c825930ff42bce28596b52dee15567f6b28f19c195e3","LICENSE-MIT":"df20e0180764bf5bd76f74d47bc9e8c0069a666401629c390003a1d5eba99c92","README.md":"f1c057bd94aff0d98bcd7267655bb8af4c9c81a643423c5948f711e199945905","benches/all.rs":"0e0458780fa24e55402b11fdbc6ef2191b399459461a9f909a516363e824c838","src/lib.rs":"6915d0f08ccd34a144b017c89f077ffba05654a62a2ce82924e68674f05e0d6a"},"package":"9a1bb320f97e6edf9f756bf015900038e43c7700e059688e5724a928c8f3b8d5"} \ No newline at end of file +{"files":{"Cargo.toml":"a140f9df40d83c3f3c39864df0e272bde3e210ad9d37cf90342c45f137c5b1aa","LICENSE-APACHE":"87cb0d734c723c083e51c825930ff42bce28596b52dee15567f6b28f19c195e3","LICENSE-MIT":"df20e0180764bf5bd76f74d47bc9e8c0069a666401629c390003a1d5eba99c92","README.md":"f1c057bd94aff0d98bcd7267655bb8af4c9c81a643423c5948f711e199945905","benches/all.rs":"0e0458780fa24e55402b11fdbc6ef2191b399459461a9f909a516363e824c838","src/lib.rs":"5f96ad55ac916b63ef051373994c08a0bfaa3b85a5bf031a579dc23163c47267"},"package":"619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"} \ No newline at end of file diff --git a/vendor/askama_escape/Cargo.toml b/vendor/askama_escape/Cargo.toml index 8ed339415..d4944ed6e 100644 --- a/vendor/askama_escape/Cargo.toml +++ b/vendor/askama_escape/Cargo.toml @@ -12,7 +12,7 @@ [package] edition = "2018" name = "askama_escape" -version = "0.10.2" +version = "0.10.3" description = "Optimized HTML escaping code, extracted from Askama" homepage = "https://github.com/djc/askama" documentation = "https://docs.rs/askama_escape" @@ -26,5 +26,8 @@ name = "all" harness = false [dev-dependencies.criterion] version = "0.3" + +[features] +json = [] [badges.maintenance] status = "actively-developed" diff --git a/vendor/askama_escape/src/lib.rs b/vendor/askama_escape/src/lib.rs index 4643390ca..178884308 100644 --- a/vendor/askama_escape/src/lib.rs +++ b/vendor/askama_escape/src/lib.rs @@ -1,12 +1,11 @@ -#![no_std] +#![cfg_attr(not(any(feature = "json", test)), no_std)] #![deny(elided_lifetimes_in_paths)] - -#[cfg(test)] -extern crate std; +#![deny(unreachable_pub)] use core::fmt::{self, Display, Formatter, Write}; use core::str; +#[derive(Debug)] pub struct MarkupDisplay where E: Escaper, @@ -35,6 +34,7 @@ where } } + #[must_use] pub fn mark_safe(mut self) -> MarkupDisplay { self.value = match self.value { DisplayValue::Unsafe(t) => DisplayValue::Safe(t), @@ -64,12 +64,13 @@ where } } +#[derive(Debug)] pub struct EscapeWriter<'a, E, W> { fmt: W, escaper: &'a E, } -impl<'a, E, W> Write for EscapeWriter<'a, E, W> +impl Write for EscapeWriter<'_, E, W> where W: Write, E: Escaper, @@ -86,6 +87,7 @@ where Escaped { string, escaper } } +#[derive(Debug)] pub struct Escaped<'a, E> where E: Escaper, @@ -94,7 +96,7 @@ where escaper: E, } -impl<'a, E> Display for Escaped<'a, E> +impl Display for Escaped<'_, E> where E: Escaper, { @@ -170,6 +172,57 @@ pub trait Escaper { const FLAG: u8 = b'>' - b'"'; +/// Escape chevrons, ampersand and apostrophes for use in JSON +#[cfg(feature = "json")] +#[derive(Debug, Clone, Default)] +pub struct JsonEscapeBuffer(Vec); + +#[cfg(feature = "json")] +impl JsonEscapeBuffer { + pub fn new() -> Self { + Self(Vec::new()) + } + + pub fn finish(self) -> String { + unsafe { String::from_utf8_unchecked(self.0) } + } +} + +#[cfg(feature = "json")] +impl std::io::Write for JsonEscapeBuffer { + fn write(&mut self, bytes: &[u8]) -> std::io::Result { + macro_rules! push_esc_sequence { + ($start:ident, $i:ident, $self:ident, $bytes:ident, $quote:expr) => {{ + if $start < $i { + $self.0.extend_from_slice(&$bytes[$start..$i]); + } + $self.0.extend_from_slice($quote); + $start = $i + 1; + }}; + } + + self.0.reserve(bytes.len()); + let mut start = 0; + for (i, b) in bytes.iter().enumerate() { + match *b { + b'&' => push_esc_sequence!(start, i, self, bytes, br#"\u0026"#), + b'\'' => push_esc_sequence!(start, i, self, bytes, br#"\u0027"#), + b'<' => push_esc_sequence!(start, i, self, bytes, br#"\u003c"#), + b'>' => push_esc_sequence!(start, i, self, bytes, br#"\u003e"#), + _ => (), + } + } + if start < bytes.len() { + self.0.extend_from_slice(&bytes[start..]); + } + Ok(bytes.len()) + } + + fn flush(&mut self) -> std::io::Result<()> { + Ok(()) + } +} + #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3