Skip to content

Commit

Permalink
Add ., -, and _ to set of unescaped characters in urlencode (#72
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lucky committed Aug 21, 2022
1 parent 3dd6f38 commit b11289f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 6 additions & 2 deletions minijinja/src/filters.rs
Expand Up @@ -688,8 +688,12 @@ mod builtins {
#[cfg_attr(docsrs, doc(cfg(all(feature = "builtins", feature = "urlencode"))))]
#[cfg(feature = "urlencode")]
pub fn urlencode(_: &State, value: Value) -> Result<String, Error> {
const SET: &percent_encoding::AsciiSet =
&percent_encoding::NON_ALPHANUMERIC.remove(b'/').add(b' ');
const SET: &percent_encoding::AsciiSet = &percent_encoding::NON_ALPHANUMERIC
.remove(b'/')
.remove(b'.')
.remove(b'-')
.remove(b'_')
.add(b' ');
match &value.0 {
ValueRepr::None | ValueRepr::Undefined => Ok("".into()),
ValueRepr::Bytes(b) => Ok(percent_encoding::percent_encode(b, SET).to_string()),
Expand Down
2 changes: 1 addition & 1 deletion minijinja/tests/inputs/filters.txt
Expand Up @@ -47,7 +47,7 @@ d: {{ undefined|d == "" }}
json: {{ map|tojson }}
json-pretty: {{ map|tojson(true) }}
json-scary-html: {{ scary_html|tojson }}
urlencode: {{ "hello world/baz"|urlencode }}
urlencode: {{ "hello world/foo-bar_baz.txt"|urlencode }}
urlencode-kv: {{ dict(a="x y", b=2, c=3)|urlencode }}
batch: {{ range(10)|batch(3) }}
batch-fill: {{ range(10)|batch(3, '-') }}
Expand Down
@@ -1,9 +1,7 @@
---
source: minijinja/tests/test_templates.rs
assertion_line: 44
expression: "&rendered"
input_file: minijinja/tests/inputs/filters.txt

---
lower: bird
upper: BIRD
Expand Down Expand Up @@ -49,7 +47,7 @@ json-pretty: {
"c": "d"
}
json-scary-html: "\u003c\u003e\u0026\u0027"
urlencode: hello%20world/baz
urlencode: hello%20world/foo-bar_baz.txt
urlencode-kv: a=x%20y&b=2&c=3
batch: [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
batch-fill: [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, "-", "-"]]
Expand Down

0 comments on commit b11289f

Please sign in to comment.