From 40dfa4dd9886019630e7d24880de987e2a7f8ad1 Mon Sep 17 00:00:00 2001 From: Dominic Date: Mon, 28 Feb 2022 14:42:31 +0100 Subject: [PATCH] rename feature to urlencode --- Cargo.toml | 4 ++-- src/builtins/filters/string.rs | 18 +++++++++--------- src/tera.rs | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9572aee2..2e2df67d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,8 +43,8 @@ tempfile = "3" [features] default = ["builtins"] -builtins = ["builtins_urlencode", "slug", "humansize", "chrono", "chrono-tz", "rand"] -builtins_urlencode = ["percent-encoding"] +builtins = ["urlencode", "slug", "humansize", "chrono", "chrono-tz", "rand"] +urlencode = ["percent-encoding"] preserve_order = ["serde_json/preserve_order"] [badges] diff --git a/src/builtins/filters/string.rs b/src/builtins/filters/string.rs index e4d5599e..e92ffa9a 100644 --- a/src/builtins/filters/string.rs +++ b/src/builtins/filters/string.rs @@ -6,23 +6,23 @@ use regex::{Captures, Regex}; use serde_json::value::{to_value, Value}; use unic_segment::GraphemeIndices; -#[cfg(feature = "builtins_urlencode")] +#[cfg(feature = "urlencode")] use percent_encoding::{percent_encode, AsciiSet, NON_ALPHANUMERIC}; use crate::errors::{Error, Result}; use crate::utils; /// https://url.spec.whatwg.org/#fragment-percent-encode-set -#[cfg(feature = "builtins_urlencode")] +#[cfg(feature = "urlencode")] const FRAGMENT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS.add(b' ').add(b'"').add(b'<').add(b'>').add(b'`'); /// https://url.spec.whatwg.org/#path-percent-encode-set -#[cfg(feature = "builtins_urlencode")] +#[cfg(feature = "urlencode")] const PATH_ENCODE_SET: &AsciiSet = &FRAGMENT_ENCODE_SET.add(b'#').add(b'?').add(b'{').add(b'}'); /// https://url.spec.whatwg.org/#userinfo-percent-encode-set -#[cfg(feature = "builtins_urlencode")] +#[cfg(feature = "urlencode")] const USERINFO_ENCODE_SET: &AsciiSet = &PATH_ENCODE_SET .add(b'/') .add(b':') @@ -38,7 +38,7 @@ const USERINFO_ENCODE_SET: &AsciiSet = &PATH_ENCODE_SET /// Same as Python quote /// https://github.com/python/cpython/blob/da27d9b9dc44913ffee8f28d9638985eaaa03755/Lib/urllib/parse.py#L787 /// with `/` not escaped -#[cfg(feature = "builtins_urlencode")] +#[cfg(feature = "urlencode")] const PYTHON_ENCODE_SET: &AsciiSet = &USERINFO_ENCODE_SET .remove(b'/') .add(b':') @@ -214,7 +214,7 @@ pub fn capitalize(value: &Value, _: &HashMap) -> Result { } /// Percent-encodes reserved URI characters -#[cfg(feature = "builtins_urlencode")] +#[cfg(feature = "urlencode")] pub fn urlencode(value: &Value, _: &HashMap) -> Result { let s = try_get_value!("urlencode", "value", String, value); let encoded = percent_encode(s.as_bytes(), &PYTHON_ENCODE_SET).to_string(); @@ -222,7 +222,7 @@ pub fn urlencode(value: &Value, _: &HashMap) -> Result { } /// Percent-encodes all non-alphanumeric characters -#[cfg(feature = "builtins_urlencode")] +#[cfg(feature = "urlencode")] pub fn urlencode_strict(value: &Value, _: &HashMap) -> Result { let s = try_get_value!("urlencode_strict", "value", String, value); let encoded = percent_encode(s.as_bytes(), &NON_ALPHANUMERIC).to_string(); @@ -596,7 +596,7 @@ mod tests { } } - #[cfg(feature = "builtins_urlencode")] + #[cfg(feature = "urlencode")] #[test] fn test_urlencode() { let tests = vec![ @@ -620,7 +620,7 @@ mod tests { } } - #[cfg(feature = "builtins_urlencode")] + #[cfg(feature = "urlencode")] #[test] fn test_urlencode_strict() { let tests = vec![ diff --git a/src/tera.rs b/src/tera.rs index 4bb944e6..c53ee0e2 100644 --- a/src/tera.rs +++ b/src/tera.rs @@ -580,9 +580,9 @@ impl Tera { self.register_filter("linebreaksbr", string::linebreaksbr); self.register_filter("striptags", string::striptags); self.register_filter("spaceless", string::spaceless); - #[cfg(feature = "builtins_urlencode")] + #[cfg(feature = "urlencode")] self.register_filter("urlencode", string::urlencode); - #[cfg(feature = "builtins_urlencode")] + #[cfg(feature = "urlencode")] self.register_filter("urlencode_strict", string::urlencode_strict); self.register_filter("escape", string::escape_html); self.register_filter("escape_xml", string::escape_xml);