48 Commits

Author SHA1 Message Date
dependabot[bot]
f0a1fa467d build(deps): update criterion requirement from 0.6 to 0.7
Updates the requirements on [criterion](https://github.com/bheisler/criterion.rs) to permit the latest version.
- [Changelog](https://github.com/bheisler/criterion.rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bheisler/criterion.rs/compare/0.6.0...0.7.0)

---
updated-dependencies:
- dependency-name: criterion
  dependency-version: 0.7.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-25 23:36:35 +02:00
Guillaume Gomez
79d8f8886b Update to rust edition 2024 and to MSRV 1.88 2025-07-07 22:23:29 +02:00
René Kijewski
75dd2c92f3 Update dependencies
* Update version-incompatible dependencies in examples.
* Update version-incompatible dev-dependencies.
* Replaced deprecated `criterion::black_box`.
* Add `features = "simd"` to `winnow`. This adds a transitive
  dependency to `memchr`, on which we already depend on directly.
2025-05-18 23:06:41 +02:00
Guillaume Gomez
04a4d5b020 Update MSRV to 1.83 2025-04-22 11:34:55 +02:00
René Kijewski
697862a76c Bump version number to 0.13.0 2025-03-27 17:22:37 +01:00
René Kijewski
f564e724e1 Revive askama_escaped
We adopted `askama_escape` with the other askama crates. It was not
updated for quite some time, but still gets 25k+ downloads / day Mon to
Fri.

This PR re-adds the crate using our current HTML escaping function.
2025-03-21 22:45:25 +01:00
Guillaume Gomez
2d80cc3524 Rename everything to rinja 2024-06-17 15:58:52 +02:00
René Kijewski
78cec97604 Make |tojson filter faster
This PR changes the filter `|tojson` so that it does not collect the
serialized data into a string, but writes the data into the target
writer directly.

This makes the benchmark run 81% (only serializing) or 39% (serializing
and escaping for HTML) faster. The benchmarked data is not a fair
representation for the data you would most likely serialize, though.
2024-05-01 11:08:32 +02:00
Dirkjan Ochtman
a6bc14c8ca Advertise Discord channel instead of Gitter 2023-10-03 17:39:03 +02:00
Dirkjan Ochtman
daa8d89b57 Add MSRV checking in CI
Bump MSRV to 1.65 for the use of let .. else.
2023-09-29 16:13:24 +02:00
Dirkjan Ochtman
c96fd996bb escape: simplify literals as suggested by clippy 2023-08-25 13:22:05 +02:00
dependabot[bot]
a3ff30a5ea Update criterion requirement from 0.4 to 0.5
Updates the requirements on [criterion](https://github.com/bheisler/criterion.rs) to permit the latest version.
- [Changelog](https://github.com/bheisler/criterion.rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bheisler/criterion.rs/compare/0.4.0...0.5.0)

---
updated-dependencies:
- dependency-name: criterion
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-24 09:47:44 +02:00
René Kijewski
3b830b0fee Use lookup table 2023-03-30 14:49:15 +02:00
René Kijewski
6daf343e8b Escape HTML faster
Escaped HTML characters vary in length. So, in order to select the
correct replacement two variables need to be loaded: The pointer to the
new substring and its length. Because of this the generated code is less
dense than it could be.

With this PR instead of selecting the appropriate `&str`, an `&&str` is
selected. The former consumes two words while the latter consumes only
one. Intuitively one might assume that the double dereference makes the
code slower, but the optimized lookup seems to be so much faster, so
that the change is worth its weight.

Comparing the result of `cargo bench` (best out of three runs for both):

```text
Old:  [4.3592 µs 4.3675 µs 4.3764 µs]
New:  [3.8691 µs 3.8766 µs 3.8860 µs]
Diff: [-11.24 %  -11.24 %  -12.21 % ]
```
2023-03-30 14:49:15 +02:00
Dirkjan Ochtman
3003d86264
Apply clippy suggestions for 1.67 (#769) 2023-01-30 09:51:23 +01:00
dependabot[bot]
f88403430b
Update criterion requirement from 0.3 to 0.4 (#721)
Updates the requirements on [criterion](https://github.com/bheisler/criterion.rs) to permit the latest version.
- [Release notes](https://github.com/bheisler/criterion.rs/releases)
- [Changelog](https://github.com/bheisler/criterion.rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bheisler/criterion.rs/compare/0.3.0...0.4.0)

---
updated-dependencies:
- dependency-name: criterion
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-26 15:46:12 +02:00
René Kijewski
fc779e22c3 Remove unsafe { … } code from askama_escape
Using only safe code is actually same as fast as the previous "unsafe"
code according to the crate's benchmark.

The code was extracted from [markup]'s escape function in [escape.rs],
written by Utkarsh Kukreti <utkarshkukreti@gmail.com>, licensed as
`MIT OR Apache-2.0`.

[markup]: https://crates.io/crates/markup
[escape.rs]: 8ec4042848/markup/src/escape.rs (L1-L21)
2022-04-13 13:18:27 +02:00
René Kijewski
5a141ef414 Increment patch versions of askama_{shared,escape} 2022-02-16 14:51:39 +01:00
René Kijewski
29f0c0607a Make json filter safe
Previously the built-in json filter had an issue that made it unsafe to
use in HTML data. When used in HTML attributes an attacker who is able
to supply an arbitrary string that should be JSON encoded could close
the containing HTML element e.g. with `"</div>"`, and write arbitrary
HTML code afterwards as long as they use apostrophes instead of
quotation marks. The programmer could make this use case safe by
explicitly escaping the JSON result: `{{data|json|escape}}`.

In a `<script>` context the json filter was not usable at all, because
in scripts HTML escaped entities are not parsed outside of XHTML
documents. Without using the safe filter an attacker could close the
current script using `"</script>"`.

This PR fixes the problem by always escaping less-than, greater-than,
ampersand, and apostrophe characters using their JSON unicode escape
sequence `\u00xx`. Unless the programmer explicitly uses the safe
filter, quotation marks are HTML encoded as `&quot`. In scripts the
programmer should use the safe filter, otherwise not.
2022-02-16 14:51:39 +01:00
René Kijewski
9dfe4cb39a Add #![deny(unreachable_pub)] to all crates 2022-01-06 13:05:24 +01:00
René Kijewski
f4254dedcf Omit implicit lifetimes 2022-01-06 13:05:24 +01:00
René Kijewski
697f92dc27 Add #[derive(Debug)] for public types 2022-01-06 13:05:24 +01:00
Dirkjan Ochtman
4d936524ba Fix suggestions from nightly clippy 2021-12-22 12:30:43 +01:00
Dirkjan Ochtman
88cb31516e Remove authors from Cargo metadata (see RFC 3052) 2021-11-24 20:40:59 -08:00
Dirkjan Ochtman
47c6bca8ac Bump version numbers in anticipation of beta release 2021-08-21 19:12:41 +02:00
Dirkjan Ochtman
8bb3de0a3e Stop eliding lifetimes in paths 2021-07-01 16:10:43 +02:00
Alex Wennerberg
c0e75554d2
Remove forward-slash escape (#486)
This was based off of the OWASP XSS prevention cheat sheet --
https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#output-encoding-rules-summary

However, there isn't really any attack vector based on forward slash alone, and
it's being removed in the next version of that document.

> There is no proof that escaping forward slash will improve
> defense against XSS, if all other special characters are escaped
> properly, but it forces developers to use non-standard implementation of
> the HTML escaping, what increases the risk of the mistake and makes the
> implementation harder.

https://github.com/OWASP/CheatSheetSeries/pull/516
2021-05-17 21:33:47 +02:00
Wim Looman
54a2046edc Add no_std support to askama_escape 2021-01-15 23:35:33 +01:00
Dirkjan Ochtman
37fb6413b6 Add askama_escape README to crate metadata 2020-06-30 13:38:17 +02:00
Dirkjan Ochtman
ab12a29ab3 Add README files for subcrates 2020-06-30 13:35:53 +02:00
Dirkjan Ochtman
073788d10d Bump version numbers 2020-06-30 13:14:02 +02:00
Dirkjan Ochtman
6c4132eedc Add license files to each crate (fixes #339) 2020-06-30 12:09:14 +02:00
Ciprian Dorin Craciun
b5ecf9bd87 Update EscapeWriter HTML implementation to not output empty strings 2020-05-24 20:06:44 +02:00
Dirkjan Ochtman
1f431c75a5 Remove obsolete CI badges 2020-01-15 13:55:44 +01:00
Dirkjan Ochtman
d89758c9fe Bump version numbers to 0.9.0 2020-01-15 13:55:33 +01:00
dependabot-preview[bot]
66274b7c8e Update criterion requirement from 0.2 to 0.3
Updates the requirements on [criterion](https://github.com/bheisler/criterion.rs) to permit the latest version.
- [Release notes](https://github.com/bheisler/criterion.rs/releases)
- [Changelog](https://github.com/bheisler/criterion.rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bheisler/criterion.rs/compare/0.2.0...0.3.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-26 09:48:52 +02:00
Dirkjan Ochtman
0efd48e037 Update formatting 2019-07-25 22:55:55 +02:00
Ram Kaniyur
f0c80e854f Change askama_escape to require UTF-8 strings 2019-06-14 13:44:06 +02:00
Dirkjan Ochtman
744127bd1c Bump versions in anticipation of 0.8.0 release 2019-01-17 17:24:04 +01:00
Dirkjan Ochtman
467f4ade19 Specify a trait that handles the output format's escaping 2019-01-12 09:16:20 +01:00
Dirkjan Ochtman
a2bdf3b138 Slightly simplify escaping code 2019-01-12 09:16:20 +01:00
yossyJ
ed47f17f3c Improved rendering time (#190)
* Improved rendering time

* Fix useless codes
2019-01-06 14:28:22 +01:00
Dirkjan Ochtman
5549f9a3cd Use 2018 edition idioms 2018-12-08 21:43:20 +01:00
Dirkjan Ochtman
d042c5d758 Upgrade to 2018 edition 2018-12-08 21:43:20 +01:00
Dirkjan Ochtman
e7fde0733b Move escaping benchmarks into askama_escape crate 2018-11-14 16:18:19 +01:00
Dirkjan Ochtman
6a2cff0ab6 Tweak metadata for new askama_escape crate 2018-11-07 21:37:07 +01:00
Dirkjan Ochtman
460079e347 Clean up unused features 2018-11-07 21:37:07 +01:00
bott
8224f06f3e Create askama_escape crate 2018-11-07 17:58:13 +01:00