René Kijewski
76b26cd5fa
parser: str lit must not be followed by suffix#
...
Resolves <https://issues.oss-fuzz.com/issues/426509683 >.
2025-06-21 19:43:28 +02:00
René Kijewski
2e510b0862
Remove normalize_identifier
benchmark
...
The benchmark is overly specific.
2025-06-20 16:19:24 +02:00
Guillaume Gomez
1275b58ccb
Merge pull request #486 from Kijewski/pr-more-core
...
Filters `linebreaks`, `paragraphbreaks` and `linebreaksbr` only need `core`
2025-06-17 16:54:01 +02:00
René Kijewski
b6acf7b3a8
parser: simplify {# comment #}
parsing
...
`winnow`'s `take_until` with feature `simd` enabled is implemented like
our "optimized" `skip_till`. There is no need to reinvent the wheel.
2025-06-16 23:49:58 +02:00
René Kijewski
568ced0c55
parser: recognize comments in macro calls
...
Fixes issue <https://issues.oss-fuzz.com/issues/425145246 >
2025-06-16 23:49:47 +02:00
Guillaume Gomez
e329f98433
Merge pull request #484 from Kijewski/pr-u+10ffff
...
parser: U+10FFFF is the highest Unicode codepoint
2025-06-16 16:50:36 +02:00
René Kijewski
b9490c4b5d
Filter paragraphbreaks
only needs core
2025-06-14 14:57:55 +02:00
René Kijewski
00b640c93b
parser: better error message for bare CRs
2025-06-13 22:19:17 +02:00
René Kijewski
9ffa6b954c
parser: U+10FFFF is the highest Unicode codepoint
...
Fix a small typo: parsing '\u{123456}` should parse up to 6 characters,
inclusively.
2025-06-13 11:32:51 +02:00
René Kijewski
341b850351
parser: reject isolated CRs in string literals
...
According to <https://doc.rust-lang.org/reference/tokens.html#string-literals >.
Fixes <https://github.com/askama-rs/askama/issues/482 >.
Fixes <https://issues.oss-fuzz.com/issues/424227903 >.
2025-06-13 06:17:12 +02:00
René Kijewski
50e0a96481
Rename LoopItem::index
to LoopItem::index0
...
That's what the element is called in the template syntax.
Also refactor `Generator::visit_attr()` at bit to make it more readable.
Also add `__askama` prefix to `_len`.
2025-06-11 18:53:42 +02:00
René Kijewski
532e343c40
parser: reject illegal string literals
2025-06-09 19:24:08 +02:00
René Kijewski
66ce299a4a
parser: in macro calls reject cstrings with NULs
2025-06-09 19:24:07 +02:00
Michael Pollind
df54534ae6
bugfix: resolve with macro with call after caller
...
https://github.com/askama-rs/askama/issues/467
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-06-01 21:05:06 +02:00
Guillaume Gomez
741ff53a88
Add regression tests for mutable variables
2025-06-01 16:26:57 +02:00
Guillaume Gomez
9ee2afecfa
Add support for mutable variables
2025-06-01 16:26:57 +02:00
René Kijewski
377253945e
crate!
etc are invalid macro names
2025-05-23 21:01:00 +02:00
Guillaume Gomez
657dcea10f
Merge pull request #422 from pollend/feature/add-support-for-caller
...
feat: add caller pattern from jinja
2025-05-23 13:57:18 +02:00
René Kijewski
eaccbb02ae
Comparison operators cannot be chained
2025-05-23 01:26:19 +02:00
Guillaume Gomez
1acbc33383
Improve error output
2025-05-22 23:11:46 +02:00
Guillaume Gomez
aefd0848af
Fix test_short_circuit
test
2025-05-22 23:07:27 +02:00
Guillaume Gomez
3ab930ded0
Fix handling of endcall
whitespace characters
2025-05-22 22:50:40 +02:00
Michael Pollind
f08ca469c9
add more test add reserved word caller
...
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
c4fcd4781a
address comments
...
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
0547c2ee88
fix caller logic
...
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
ef489b60f6
add test cases and rework spaces
...
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
8862325e9b
tweak test
...
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
ce73e73720
feat: add caller pattern and adjust syntax to closer match jinja
...
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
b8c85a07bd
feat: add caller pattern for macro
...
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:39 +02:00
René Kijewski
f92ed0a074
Deny self
etc. as path element
2025-05-20 21:20:55 +02:00
René Kijewski
1b2c54620e
name
is its own span
2025-05-20 21:19:57 +02:00
Guillaume Gomez
5099820722
Add test to ensure that self
can be used as match
argument
2025-05-20 18:37:39 +02:00
Guillaume Gomez
8b05a5c118
Add ui tests for crate
, Self
and super
as identifiers
2025-05-20 18:37:39 +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
René Kijewski
3775f4e3a3
Use unicode-ident
to determine what is an identifier
...
Resolves <https://github.com/askama-rs/askama/issues/442 >.
The performance is actually slightly better than before. `unicode-ident`
is highly optimized and jump free.
One test from a fuzzer outcome had to be deleted, because it contained
identifiers that weren't actually identifiers. There is still a test
that tests the same problem, but every identifier is simply `x`. In
another fuzzed test a character [`U+E0049`] was removed.
[`U+E0049`]: https://en.wikipedia.org/w/index.php?oldid=1278382889
<details>
<summary>Benchmark results</summary>
```text
$ cd askama_parser && cargo bench
librustdoc/all time: [184.47 µs 185.30 µs 186.08 µs]
thrpt: [75.887 MiB/s 76.207 MiB/s 76.548 MiB/s]
change:
time: [−1.4364% −0.9672% −0.4738%] (p = 0.00 < 0.05)
thrpt: [+0.4761% +0.9767% +1.4573%]
Change within noise threshold.
librustdoc/item_info time: [3.3880 µs 3.3892 µs 3.3906 µs]
thrpt: [46.409 MiB/s 46.428 MiB/s 46.445 MiB/s]
change:
time: [−3.8735% −3.5927% −3.2949%] (p = 0.00 < 0.05)
thrpt: [+3.4071% +3.7266% +4.0296%]
Performance has improved.
librustdoc/item_union time: [20.052 µs 20.087 µs 20.126 µs]
thrpt: [49.044 MiB/s 49.140 MiB/s 49.224 MiB/s]
change:
time: [−2.2419% −1.8647% −1.5113%] (p = 0.00 < 0.05)
thrpt: [+1.5345% +1.9002% +2.2933%]
Performance has improved.
librustdoc/page time: [85.828 µs 86.157 µs 86.518 µs]
thrpt: [71.571 MiB/s 71.871 MiB/s 72.147 MiB/s]
change:
time: [−1.2728% −0.7668% −0.2512%] (p = 0.00 < 0.05)
thrpt: [+0.2518% +0.7727% +1.2892%]
Change within noise threshold.
librustdoc/print_item time: [10.065 µs 10.101 µs 10.138 µs]
thrpt: [93.132 MiB/s 93.469 MiB/s 93.806 MiB/s]
change:
time: [−3.3793% −2.8352% −2.3267%] (p = 0.00 < 0.05)
thrpt: [+2.3821% +2.9180% +3.4975%]
Performance has improved.
librustdoc/short_item_info
time: [9.0741 µs 9.1018 µs 9.1377 µs]
thrpt: [99.148 MiB/s 99.540 MiB/s 99.843 MiB/s]
change:
time: [−4.7480% −4.2335% −3.7763%] (p = 0.00 < 0.05)
thrpt: [+3.9245% +4.4207% +4.9847%]
Performance has improved.
librustdoc/sidebar time: [21.468 µs 21.555 µs 21.648 µs]
thrpt: [57.004 MiB/s 57.252 MiB/s 57.482 MiB/s]
change:
time: [−3.7641% −3.0465% −2.4191%] (p = 0.00 < 0.05)
thrpt: [+2.4791% +3.1423% +3.9114%]
Performance has improved.
librustdoc/source time: [7.9602 µs 7.9780 µs 7.9929 µs]
thrpt: [92.230 MiB/s 92.403 MiB/s 92.609 MiB/s]
change:
time: [−1.6386% −1.0684% −0.5875%] (p = 0.00 < 0.05)
thrpt: [+0.5910% +1.0799% +1.6659%]
Change within noise threshold.
librustdoc/type_layout_size
time: [4.7821 µs 4.7915 µs 4.8017 µs]
thrpt: [56.406 MiB/s 56.526 MiB/s 56.637 MiB/s]
change:
time: [−1.9743% −1.4867% −1.0153%] (p = 0.00 < 0.05)
thrpt: [+1.0257% +1.5091% +2.0141%]
Performance has improved.
librustdoc/type_layout time: [15.022 µs 15.051 µs 15.076 µs]
thrpt: [178.57 MiB/s 178.88 MiB/s 179.22 MiB/s]
change:
time: [−1.5028% −1.0358% −0.5705%] (p = 0.00 < 0.05)
thrpt: [+0.5738% +1.0466% +1.5257%]
Change within noise threshold.
```
</details>
2025-05-18 23:04:47 +02:00
René Kijewski
ab798e2482
Allow filters with explicit path
...
IMHO that makes custom filters much easier to use.
2025-05-17 13:20:54 +02:00
René Kijewski
6ce85f318c
Make code generator re-usable for other projects
...
This PR
* removes the crate `askama_derive_standalone`,
* makes `askama_derive` a normal library, and
* adds the proc-macro crate `askama_macros`,
Before, it was not possible for another crate to re-export
`askama::Template` in a useful way, because the generated code assumes
that it has access to an `extern crate askama`.
`askama_derive` will export the function `derive_template()` like
`askama_derive_standalone` did, but it has an additional argument to
accept a `TokenStream` that should contain (an) statement(s) to define
the identifier `askama`, e.g. `quote! { extern crate askama; }`.
The new proc-macro crate `askama_macros` now defines the derive-macro
`Template` by calling `askama_derive::derive_template()`.
Prior art: [`encase`] → [`encase_derive`] → [`encase_derive_impl`];
[2298a3e].
[`encase`]: <https://crates.io/crates/encase/0.11.0 >
[`encase_derive`]: <https://crates.io/crates/encase_derive/0.11.0 >
[`encase_derive_impl`]: <https://crates.io/crates/encase_derive_impl/0.11.0 >
[2298a3e]: <2298a3efd5
>
2025-05-17 13:20:21 +02:00
C0D3 M4513R
c31fce773e
Relax Sized constraint on impl FastWritable for Cow
( #432 )
...
* Add test to ensure `Cow<'_, str>` implements `FastWritable`
* Relax Sized constraint on `impl FastWritable for Cow`
* Run rustfmt
Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com>
* Put "test" in a const block.
* Update cow_str_implements_fast_writable.rs
Co-authored-by: René Kijewski <Kijewski@users.noreply.github.com>
---------
Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com>
Co-authored-by: René Kijewski <Kijewski@users.noreply.github.com>
2025-05-07 17:11:45 +02:00
René Kijewski
a7c55f77fe
generator: fix ensure_no_named_arguments()
test
...
The wrong `Expr` variant was tested.
2025-05-02 00:54:18 +02:00
René Kijewski
72bbe3ede1
Bump version number to v0.14.0
2025-04-22 23:37:23 +02:00
Guillaume Gomez
6a16256f24
Fix new clippy lints
2025-04-22 11:34:55 +02:00
Guillaume Gomez
04a4d5b020
Update MSRV to 1.83
2025-04-22 11:34:55 +02:00
Guillaume Gomez
6f912abee6
Move FastWritable
into askama
root
2025-04-22 11:33:57 +02:00
Guillaume Gomez
7c5deda4c1
Rename pluralize
arguments into singular
and plural
2025-04-21 23:11:24 +02:00
René Kijewski
b402936db3
generator: add named arguments for filters
2025-04-21 23:11:24 +02:00
René Kijewski
4be302338a
generator: do argument coercion for |truncate
/ |center
...
Don't simply pass any arguments to the filter. The error message won't
be useful otherwise. Also ensure that the argument is a `usize`.
2025-04-21 23:11:24 +02:00
René Kijewski
94fddd4df5
book: add page about FastWritable
2025-04-19 22:09:28 +02:00
René Kijewski
ba33974996
Let |indent
use AsIndent
2025-04-17 15:07:21 +02:00
René Kijewski
c6d45e1cdc
Always supply values
to custom filters
2025-04-15 17:15:47 +02:00
René Kijewski
f7fc39d138
Implement |wordcount
filter with access to runtime values
2025-04-15 13:24:19 +02:00