-
Notifications
You must be signed in to change notification settings - Fork 12
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 HTML safe types #54
Conversation
ae52280
to
1f5bfeb
Compare
1f5bfeb
to
d436bef
Compare
I'll review this one once #53 is merged if you don't mind. ;) |
d436bef
to
e4f28d0
Compare
Please add an entry in the filters chapter to let users (like me hehehe) know how to use this feature. |
This PR adds an `HtmlSafeMarker` trait. Types that implement this marker are know to never generate strings containing the characters `< > & " '`, so they don't have to be escaped. All glory goes to \@dtolnay's ["Autoref-based stable specialization"][1] case study / blog entry. [1]: <https://github.com/dtolnay/case-studies/blob/0a9f083f334e53bc854a80022b1984b1bae36ef6/autoref-specialization/README.md>
Also a documentation that there is no `Unsafe` wrapper, because that's the default anyway.
e4f28d0
to
d946e1e
Compare
Yeah, I guess the usage was not entirely self-explanatory. :D Added a section to the book. I also renamed |
I added more tests, and replaced |
rinja/src/filters/escape.rs
Outdated
/// "<div class='<script>'></div>", | ||
/// ); | ||
/// ``` | ||
pub struct MaybeSafe<T: fmt::Display> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this type would be better as an enum (with variables Safe
and NeedsEscaping
?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right. 👍 It's less error prone. And actually its easier to use I just noticed while implementing the change.
Looks good to me, thanks! Please merge once CI is happy. |
8d4cfe4
to
92157ee
Compare
This PR adds an
HtmlSafeMarker
trait. Types that implement this marker are know to never generate strings containing the characters< > & " '
, so they don't have to be escaped.All glory goes to @dtolnay's "Autoref-based stable specialization" case study / blog entry.
This PR is built on #53.
Resolves #51.