2191 Commits

Author SHA1 Message Date
René Kijewski
5b4df98ff6 ci: group checks in fast, avg and slow 2025-01-04 19:08:16 +01:00
René Kijewski
d3a1afd99d fuzzing: update corpus 2025-01-04 18:25:38 +01:00
René Kijewski
fff55f2a1d
Merge pull request #304 from Kijewski/pr-excessive-filter-block
parser: fix excessive filter blocks
2025-01-04 11:53:26 +01:00
René Kijewski
053366821b
Merge pull request #303 from Kijewski/pr-upgrade
book: add `upgrading.md`
2025-01-04 11:52:52 +01:00
René Kijewski
ff25aaab2a parser: fix excessive filter blocks
A `{% filter %}` block could have an unbound number of filters chained
one after another. This chain would wind up as a nested structure on the
heap. When dropped, this would cause a stackoverflow.

Resolves <https://issues.oss-fuzz.com/issues/386547457>.
2025-01-04 11:23:54 +01:00
René Kijewski
d1287adf80 fuzzing: add option to write out fuzzed scenarios 2025-01-04 11:03:16 +01:00
René Kijewski
6be9f7104b book: add upgrading.md 2025-01-04 00:13:21 +01:00
René Kijewski
0373645eb9
Merge pull request #301 from Kijewski/pr-digits
Speed-up HTML escaping a bit
2025-01-01 18:09:37 +01:00
René Kijewski
39647e57a6 Speed-up HTML escaping a bit
This PR adds an `enum Digits` that contains all possible values for
two-digit decimal numbers: `b"00" ..= b"99"`. This seems to enable rust
and/or llvm to make better use of niches. Previously there were no
niches, and we compared against `0` manually. Now most of the u16-space
are niches.

```text
Escaping                time:   [3.3437 µs 3.3497 µs 3.3578 µs]
                        change: [-18.807% -18.620% -18.452%] (p = 0.00 < 0.05)
                        Performance has improved.
```
2025-01-01 17:55:34 +01:00
Guillaume Gomez
8d6279d9c8
Merge pull request #279 from GuillaumeGomez/block_in_include
Fix `block_in_include` and add explanations on what is going on
2025-01-01 12:15:33 +01:00
René Kijewski
d254942dbc Add jinja2 tests to verify that jinja2 renders the same 2025-01-01 09:31:52 +01:00
René Kijewski
97ecbe6dba
Merge pull request #299 from Kijewski/pr-issue-283
derive: keep track of called macros
2024-12-29 19:38:03 +01:00
René Kijewski
9336435859 derive: keep track of called macros
Recursive macro calls, direct and indirect, would cause a stackoverflow.

This PR lets the macro call handler keep track of the stack of called
macros we are currently in, so we can abort with an error message
instead of panicking.
2024-12-29 07:52:21 +01:00
Guillaume Gomez
889b2c5611
Merge pull request #297 from Kijewski/pr-fuzz-6098564903665664
parser: use drop guards to track nesting level
2024-12-27 11:03:40 +01:00
René Kijewski
4b8bd45844 parser: use drop guards to track nesting level
Not for all operations the nesting level was incremented when needed
and/or the un-incremented nesting level was used in subfunction calls.
Binary operators such as `*` did not properly increment the nesting
level.

This PR changes `Level` in such a way that it can be used to keep track
of the nesting level when used in a loop. It is now impossible to
accidentally refer to an old nesting level value.

Resolves <https://issues.oss-fuzz.com/issues/385256115>.
2024-12-27 04:31:24 +01:00
Guillaume Gomez
802d980a47
Merge pull request #296 from GuillaumeGomez/if-let-chain
Add full support for if let chain feature
2024-12-25 21:36:59 +01:00
Guillaume Gomez
ae59d772c4 Correctly handle bool comparisons 2024-12-25 21:18:57 +01:00
Guillaume Gomez
5deb71920d Add regression test for if let chain 2024-12-25 21:18:57 +01:00
Guillaume Gomez
2262a8d786 Move includes count test into its own function 2024-12-25 21:18:57 +01:00
Guillaume Gomez
5cc7cb2121 Add full support for if let chain feature 2024-12-25 21:18:57 +01:00
Guillaume Gomez
25593f249b
Merge pull request #295 from Kijewski/pr-split-generator
derive: split generator implementation into 3 files
2024-12-23 23:31:26 +01:00
René Kijewski
929d52f306 derive: split generator implementation into 3 files
3000 lines is much too many.
2024-12-23 19:12:43 +01:00
Guillaume Gomez
8a20caa136 Fix block_in_include and add explanations on what is going on 2024-12-22 21:11:04 +01:00
René Kijewski
222b9d23ca
Merge pull request #294 from Kijewski/pr-target-deny-kw
parser: deny all rust keywords as target names  and add `gen` to keywords
2024-12-22 00:03:29 +01:00
René Kijewski
18f1d9b343 parser: deny rust 2024 keyword gen as target name 2024-12-21 23:50:13 +01:00
René Kijewski
c80e78e8b5 parser: deny all rust keywords as target names 2024-12-21 23:49:48 +01:00
René Kijewski
d183c28012
Merge pull request #293 from GuillaumeGomez/improve-err-message
Improve reserved variable name error message
2024-12-21 23:20:29 +01:00
Guillaume Gomez
0d91bee794 Update ui tests 2024-12-21 23:06:56 +01:00
Guillaume Gomez
2a9d240ac4 Improve reserved variable name error message 2024-12-21 23:06:46 +01:00
Guillaume Gomez
d475e7a4a1
Merge pull request #292 from Kijewski/pr-target-writer
derive: reserve variable prefix `__rinja` and free name `writer`
2024-12-21 22:58:22 +01:00
René Kijewski
0cc0189927 Add missing softlinks 2024-12-21 19:55:15 +01:00
René Kijewski
e800b7ca90 derive: reserve variable prefix __rinja and free name writer 2024-12-21 19:42:03 +01:00
René Kijewski
ea4b2b3e79
Merge pull request #286 from Kijewski/pr-no-std
Make rinja `#![no_std]` compatible
2024-12-21 19:23:47 +01:00
René Kijewski
e7540e17a1 Add no-std and alloc-only tests 2024-12-21 18:53:44 +01:00
René Kijewski
fe36573926 Let operator ? only wrap the error in Box if needed
This leads to fewer needless allocations, and makes the operator `?`
usable in an no-alloc context.
2024-12-21 18:53:44 +01:00
René Kijewski
bedc31797c Make #![no_std] compatible 2024-12-21 18:53:44 +01:00
René Kijewski
f00e5e2091 Duplicate filter impl builtin.rs into alloc.rs
To make the next change more readable / easy to follow.
2024-12-21 18:53:44 +01:00
Guillaume Gomez
8cd0675de1
Merge pull request #291 from epage/winnow-06
refactor(parser): Upgrade to Winnow 0.6
2024-12-20 19:04:31 +01:00
Ed Page
64b4893f93 refactor(parser): Upgrade to Winnow 0.6 2024-12-20 10:36:24 -06:00
Ed Page
47a7334321
Upgrade from Winnow 0.4 to 0.5 (#214)
* refactor(parser): Consistently use 'i' in skip_till

* refactor(parser): Clarify second input in skip_till

* refactor(parser): Consistently use 'i' in Comment::parse::content

* refactor(parser): Clarify second input in Comment::parse::content

* refactor(parser): Rename ParseResult to InputParseResult

This leaves room for a new `ParseResult` that doesn't have the input as
we transition to the Winnow 0.5 API.

* refactor(parser): Temporarily switch from parse_next to parse_peek

In 0.4, `parse_next` and `parse_peek` are the same.
In 0.5, `parse_next`s signature will change.
By switching to `parse_peek` now, we can make it so we gradually adopt
the new `parse_next` signature.

* refactor(parser): Temporarilly add unpeeks

In 0.4, `unpeek` is a no-op.
In 0.5, the `FnMut` signature impled for `Parser` changes and `unpeek`
will take the old signature and adapt it to work.
This allows us to more gradually migrate to the new `FnMut` signature.

Yes, the name `unpeek` isn't ideal but its only transitional.

* refactor(parser): Upgrade to Winnow 0.5

Note: `tests::fuzzed_target_recursion` fails on debug builds because of
the extra overhead from the deprecated APIs adapting to their
non-deprecated forms

* refactor(parser): Update signature for 'identifier'

* refactor(parser): Update signature for 'bool_lit'

* refactor(parser): Update signature for 'num_lit_suffix'

* refactor(parser): Update body for 'num_lit::int_with_base'

* refactor(parser): Update signature for 'num_lit::float'

* refactor(parser): Update signature for 'num_lit'

* refactor(parser): Update signature for 'str_lit_without_prefix'

* refactor(parser): Update signature for 'str_lit'

* refactor(parser): Update signature for 'char_lit'

* refactor(parser): Update signature for 'Char::parse'

* refactor(parser): Update signature for 'path_or_identifier'

* refactor(parser): Update signature for 'filter'

* refactor(parser): Update signature for 'State::tag_block_start'

* refactor(parser): Update signature for 'State::tag_block_end'

* refactor(parser): Update signature for 'State::tag_comment_start'

* refactor(parser): Update signature for 'State::tag_comment_end'

* refactor(parser): Update signature for 'State::tag_expr_start'

* refactor(parser): Update signature for 'State::tag_expr_end'

* refactor(parser): Update signature for 'State::nest'

* refactor(parser): Update signature for 'Level::nest'

I had considered making the input a `&mut &str` but didn't really see
the benefit, especially at this stage.
That can always be changed later.

* refactor(parser): Update signature for 'skip_ws0'

* refactor(parser): Update signature for 'skip_ws1'

* refactor(parser): Update signature for 'separated_digits' closure

* refactor(parser): Update signature for 'skip_till' closure

* refactor(parser): Update signature for 'Target::lit'

* refactor(parser): Update signature for 'Target::unnamed'

* refactor(parser): Update signature for 'Target::named'

* refactor(parser): Update signature for 'Target::rest'

* refactor(parser): Update signature for 'collect_targets'

* refactor(parser): Update signature for 'Target::parse'

* refactor(parser): Update signature for 'Target::parse_one'

* refactor(parser): Update signature for 'Suffix::try'

* refactor(parser): Update signature for 'Suffix::call'

* refactor(parser): Update signature for 'Suffix::index'

* refactor(parser): Update signature for 'Suffix::attr'

* refactor(parser): Update signature for 'Suffix::macro'

* refactor(parser): Update signature for 'token_bitand'

* refactor(parser): Update signature for 'token_xor'

* refactor(parser): Update signature for 'Expr::char'

* refactor(parser): Update signature for 'Expr::num'

* refactor(parser): Update signature for 'Expr::str'

* refactor(parser): Update signature for 'Expr::path_var_bool'

* refactor(parser): Update signature for 'Expr::array'

* refactor(parser): Update signature for 'Expr::group'

* refactor(parser): Update signature for 'Expr::single'

* refactor(parser): Update signature for 'Expr::prefix'

* refactor(parser): Update signature for 'Expr::filtered'

* refactor(parser): Update signature for 'Expr::is_as'

* refactor(parser): Update signature for 'Expr::concat'

* refactor(parser): Update signature for 'expr_prec_layer'

* refactor(parser): Update signature for 'Suffix::parse'

* refactor(parser): Update signature for 'Expr::parse'

* refactor(parser): Update signature for 'Expr::named_argument'

* refactor(parser): Update signature for 'Expr::arguments'

* refactor(parser): Update signature for 'Expr::arguments' closure

* refactor(parser): Update signature for 'Comment::parse::tag

* refactor(parser): Update signature for 'Comment::parse::content

* refactor(parser): Update signature for 'Comment::parse'

* refactor(parser): Update signature for 'Extends::parse'

* refactor(parser): Update signature for 'Include::parse'

* refactor(parser): Update signature for 'Import::parse'

* refactor(parser): Update signature for 'Whitespace::parse'

* refactor(parser): Update signature for 'Lit::parse'

* refactor(parser): Update signature for 'Node::expr'

* refactor(parser): Update signature for 'Node::many'

* refactor(parser): Update signature for 'Node::parse'

* refactor(parser): Update signature for 'Node::parse_template'

* refactor(parser): Update signature for 'cut_node' closure

* refactor(parser): Avoid 'parse_peek' in 'cut_node'

* refactor(parser): Update signature for 'unexpected_raw_tag'

* refactor(parser): Update signature for 'unexpected_tag'

* refactor(parser): Update signature for 'check_end_name'

* refactor(parser): Update signature for 'CondTest::parse_cond'

* refactor(parser): Update signature for 'check_block_start'

* refactor(parser): Update signature for 'Loop::parse::content'

* refactor(parser): Update signature for 'Macro::parse::parameters'

* refactor(parser): Update signature for 'Loop::parse::else_block'

* refactor(parser): Update signature for 'Loop::parse::body_and_end'

* refactor(parser): Reuse built-in empty parser

* refactor(parser): Update signature for remaining '*::parse'

* refactor(parser): Resolve remaining deprecations
2024-12-20 17:25:20 +01:00
René Kijewski
ecf473e809
Merge pull request #290 from Kijewski/pr-find_template
derive: use `file_info` in `find_template`
2024-12-16 19:46:59 +01:00
René Kijewski
78ea25d48f derive: use file_info in find_template 2024-12-16 19:27:48 +01:00
René Kijewski
1e662042ac
Merge pull request #289 from LukeMathWalker/includes
Canonicalize paths to ensure includes behave as expected when folders are involved
2024-12-16 12:00:58 +01:00
René Kijewski
74bf996ff3 derive: update expected output for newer trybuild versions 2024-12-16 11:46:16 +01:00
Luca Palmieri
2cf65d18cc Fix: canonicalize paths to ensure hashmap lookups behave as expected 2024-12-16 10:48:42 +01:00
Luca Palmieri
f0ac41df30 Reproduce bug with a test 2024-12-15 12:07:11 +01:00
Guillaume Gomez
f71ce236d6
Merge pull request #287 from Kijewski/pr-urlencode-uppercase
derive: fix typo that mixes up `uppercase` and `urlencode`
2024-12-14 01:21:13 +01:00
René Kijewski
a443415dd0 derive: fix typo that mixes up uppercase and urlencode 2024-12-13 23:18:34 +01:00
Guillaume Gomez
43a0efda7c
Merge pull request #276 from Kijewski/pr-one-CompileError
derive: less `format!()`, shorter context on error
2024-12-13 12:02:49 +01:00
Guillaume Gomez
63a96256d3
Merge pull request #285 from Kijewski/pr-tomlfmt
Use cargo reference manifest section order
2024-12-13 11:55:18 +01:00