Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ., -, and _ to set of unescaped characters in urlencode #72

Merged
merged 3 commits into from Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this changed

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your version of cargo-insta is probably too old.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually in this case it's the other way round. Snapshots were made on an older insta version.

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