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

filters: proper escaping for |linebreaks and friends #77

Merged
merged 4 commits into from
Jul 13, 2024

Conversation

Kijewski
Copy link
Collaborator

@Kijewski Kijewski commented Jul 13, 2024

The filters |linebreaks, |linebreaksbr and |paragraphbreaks generate HTML code to be embedded in a page. Having to specify that the output of these filters is |safe is cumbersome. Also, these filters need to operate on already escaped HTML data. This could be done by writing {{ s|escape|linebreaks|safe }}.

This PR does the input and output formatting escaping for the user. The input gets escaped for HTML (invariant of the selected escaper), and the output gets marked as HTML safe.

Resolves #74.

The generator often takes references to the values it wants to display.
A bare `(Maybe)Safe<T>` won't likely be encountered.
@@ -254,8 +254,7 @@ fn filter_block_include() {
{% endif -%}
{% endfilter -%}
"#,
ext = "html",
print = "code"
Copy link
Contributor

Choose a reason for hiding this comment

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

Woups. :-.

@@ -311,9 +311,6 @@ const BUILT_IN_FILTERS: &[&str] = &[
"into_f64",
"into_isize",
"join",
"linebreaks",
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it still a function in generator.rs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, yes, of course.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I sorted the list while re-adding the items. Looks nicer this way. :)

The filters `|linebreaks`, `|linebreaksbr` and `|paragraphbreaks`
generate HTML code to be embedded in a page. Having to specify that the
output of these filters is `|safe` is cumbersome. Also, these filters
need to operate on already escaped HTML data. This could be done by
writing `{{ s|escape|linebreaks|safe }}`.

This PR does the input and output formatting escaping for the user. The
input gets escaped for HTML (invariant of the selected escaper), and the
output gets marked as HTML safe.
"urlencode_strict",
"urlencode",
Copy link
Contributor

Choose a reason for hiding this comment

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

You failed the sorting for this one. ;)

(0 is smaller than _ hehe)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would say the same all the time! But somehow the sort function in VS code, geany, etc. always give precedence to the longer word.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wut. Oh well.

@GuillaumeGomez
Copy link
Contributor

Looks all good to me, thanks!

@GuillaumeGomez GuillaumeGomez merged commit 8d3957d into rinja-rs:master Jul 13, 2024
17 checks passed
@Kijewski Kijewski deleted the pr-safe-paragraphbreaks branch July 13, 2024 13:02
@Kijewski
Copy link
Collaborator Author

And thank your for preventing me from introducing an bug in the built-in filters list! :D

@GuillaumeGomez
Copy link
Contributor

Sometimes my reviews are useful. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

|linebreaks, |linebreaksbr and |paragraphbreaks don't work as intended with regards to escaping
2 participants