281 Commits

Author SHA1 Message Date
max
5ee2dfbe6b Add test for macro self argument
Signed-off-by: max <gmx.sht@gmail.com>
2023-10-12 13:57:48 +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
René Kijewski
eef38cea67 Pass Node parsing level to expressions 2023-09-28 17:28:26 +02:00
René Kijewski
238e4bbad7 Limit nesting in parser nodes, too 2023-09-28 17:28:26 +02:00
René Kijewski
985eb8955f Fix parsing arrays
This change

* allows using empty arrays `[]` in expessions,
* adds a cut when the leading `[` was encountered, and
* fixes the interaction between arrays and boolean OR.

IMO the restriction that you couldn't use empty arrays is not needed.
The missing cut made error messages slictly worse if you forget to add
the closing `]`.

Filter expressions must not have white spaces before the pipe `|`. The
white space is used to tell a filter expressions, and `std::ops::Or`
apart.
2023-07-31 21:29:35 +02:00
René Kijewski
107bdfdd76 Fix parsing calls
This change:

* adds a cut when the leading `(` was encountered, and
* fixed the interaction between call expressions and boolean OR.
2023-07-31 21:29:35 +02:00
Matthew Taylor
ac8de6260e
Fix Rust macro invocations not accepting a path (#837) 2023-07-24 11:39:14 +02:00
mataha
cba1fb8e50 Allow macros to be defined and called without arguments
This commit introduces a shorthand for defining and calling macros when
using them as a reusable substitute for variables assigned complex values
(e.g. string literals with or without newline escapes). The use-case is
formatting - from my experience it's easier to visually parse a `macro`
`endmacro` block than a multiline variable assignment.

Signed-off-by: mataha <mataha@users.noreply.github.com>
2023-06-12 10:35:40 +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
Dirkjan Ochtman
239f59b9b1 Upgrade to comrak 0.18 2023-05-20 08:17:35 +02:00
Dirkjan Ochtman
5ff1926702 Update comrak to 0.17 2023-03-28 10:11:34 +02:00
Guillaume Gomez
40be079d5d Add tests for whitespace argument in template derive proc-macro 2023-03-13 14:41:05 +01:00
Guillaume Gomez
4233b3114f Update tests for whitespace characters handling 2023-03-09 13:35:00 +01:00
Andrew Dona-Couch -- GitHub drop ICE
dc864486ec
Propogate size_hint from sub-blocks (#788)
Closes #786
2023-03-06 22:18:45 +01:00
Dirkjan Ochtman
417cb924ae
Bump versions for Askama 0.12 (#784) 2023-03-03 18:50:56 +01:00
René Kijewski
c131154cb1 Update comrak dependency to 0.16 2023-01-30 14:37:56 +01:00
Dirkjan Ochtman
3003d86264
Apply clippy suggestions for 1.67 (#769) 2023-01-30 09:51:23 +01:00
René Kijewski
23326b4765 Update ui test for trybuild 1.0.76
In <https://github.com/dtolnay/trybuild/pull/219> the output of error
messages was subtly changed, because they introduced a subdirectoy in
their temp path.

This PR fixes the mismatch between the expected and the actual output.
2023-01-24 09:55:54 +01:00
dependabot[bot]
4d0b7a4bf1 Update comrak requirement from 0.14 to 0.15
Updates the requirements on [comrak](https://github.com/kivikakk/comrak) to permit the latest version.
- [Release notes](https://github.com/kivikakk/comrak/releases)
- [Changelog](https://github.com/kivikakk/comrak/blob/main/changelog.txt)
- [Commits](https://github.com/kivikakk/comrak/compare/0.14.0...0.15.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-15 06:48:54 +01:00
Dirkjan Ochtman
6f52d0eef5 chore: remove allow(clippy::disallowed_names) 2022-11-07 11:14:43 +01:00
Dirkjan Ochtman
ee4dbf0d8d chore: apply clippy suggestions for 1.65 2022-11-07 11:14:43 +01:00
Allan Zhang
1b18bab91b Version bump in README and book
I was going through the book when I saw the version was still 0.8.

This commit ensures all references to Askama version are to 0.11.2.
Most of them already were.

Merge whenever appropriate for release, #722 related
2022-10-21 13:24:39 +02: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
16a37f4097 Remove support for deprecated _parent field
The support for the magic `_parent` field is deprecated since v0.8.0
or issue #180. It's bothersome to keep this feature alive, when no-one
should be using it for 3 years.
2022-07-25 11:41:04 +02:00
René Kijewski
27447c8db1 Update to comrak v0.14 2022-07-20 15:25:17 +02:00
dependabot[bot]
ecf671945a Update comrak requirement from 0.12 to 0.13
Updates the requirements on [comrak](https://github.com/kivikakk/comrak) to permit the latest version.
- [Release notes](https://github.com/kivikakk/comrak/releases)
- [Changelog](https://github.com/kivikakk/comrak/blob/main/changelog.txt)
- [Commits](https://github.com/kivikakk/comrak/compare/0.12.0...0.13.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-07 08:08:48 +02:00
Bastien Orivel
ea66be1925 Allow {% endmacro name %}
Just migrated a repo from tera to askama and this was one of the only
things that was different. This is also coherent with `{% block %}` for
which I added the same feature years ago.
2022-04-29 13:35:20 +02:00
Guillaume Gomez
07cee10876 Add test for "minimize" config 2022-04-26 10:15:34 +02:00
Guillaume Gomez
a64a727331 Rename suppress_whitespace into whitespace and update expected values to "suppress" and "preserve" 2022-04-21 16:09:24 +02:00
Guillaume Gomez
adce026620 Add test for suppress_whitespace option 2022-04-21 10:08:42 +02: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
fd8bfa43c0 Add markdown filter 2022-02-07 22:30:37 +01:00
René Kijewski
c98f272972 Use exact trybuild version
Sometimes for no obvious reason an old version is selected and the
output is different in just about every ui test. Just pin it to the
currently newest version and test if an updated version still works when
a new version gets released.
2022-01-31 19:51:55 +01:00
René Kijewski
84fe381403 Remove panic!() in loop.cycle([]) 2022-01-31 13:12:09 +01:00
René Kijewski
cd744f0aa7 Make is_shadowing_variable() failable 2022-01-31 12:02:43 +01:00
René Kijewski
91874702f0 Allow comments in {% match %} and remove panic! 2022-01-31 11:30:35 +01:00
René Kijewski
da0b6ead0e Parse tuple expressions
Askama understands how to destructure tuples in let and match
statements, but it does not understand how to build a tuple.

This PR fixes this shortcoming.
2022-01-28 11:21:06 +01:00
René Kijewski
85ad2e6ba3
Implement error propagation expression: ? (#590)
This change allows using the operator `?` in askama expressions. It
works like the same operator in Rust: if a `Result` is `Ok`, it is
unwrapped. If it is an error, then the `render()` method fails with this
error value.
2022-01-28 10:48:46 +01:00
René Kijewski
cb351fe6b1
Unify handling of calls (#614)
Instead of having `Expr::VarCall`, `Expr::PathCall` and
`Expr::MethodCall`, this PR unifies the handling of calls by removing
the former three variants, and introducing `Expr::Call`.
2022-01-27 10:33:13 +01:00
René Kijewski
345f8432f5 Add unit tests if there is one #[template(…)] 2022-01-13 15:10:09 +01:00
Dirkjan Ochtman
5cfef325b0
Use a separate trait for object safety (#579)
This is relatively major change to the main trait's API. For context,
I always started from the concept of monomorphized traits, but later
several contributors asked about object safety. At that point I made
`Template` object-safe, and then even later added a `SizedTemplate`
to make some things easier for people who don't need object safety.

However, having object-safety in the primary trait is bad for
performance (a substantial number of calls into the virtual `Write`
trait is relatively slow), and I don't think those who don't need
object safety should pay for the cost of having it.

Additionally, I feel using associated consts for the extension and
size hint is more idiomatic than having accessor methods. I don't
know why I didn't use these from the start -- maybe associated
consts didn't exist yet, or I didn't yet know how/when to use them.
Askama is pretty old at this point...
2021-12-15 14:08:45 +01:00
René Kijewski
671bc7f32f Fix tests for new error messages in Rust nightly 2021-12-01 01:13:09 -08:00
René Kijewski
ef3e840ac4 Allow whitespace trimming in {{raw}} blocks 2021-11-29 23:53:27 +01:00
vallentin
8063e112a6 Added optional escaper tests 2021-11-19 15:30:10 +01:00
René Kijewski
f6b79cd82a Implement for … in … if … 2021-11-11 15:35:45 +01:00
René Kijewski
393a0ebc36 Add exhaustive whitespace tests for for-else 2021-11-11 15:35:45 +01:00
René Kijewski
10b2d9c615 Implement for-else
This PR implements for-else statements like in Jinja. They make it easy
to print an alternative message if the loop iterator was empty. E.g.

```rs
{% for result in result %}
  <li>{{ result }}</li>
{% else %}
  <li><em>no results</em></li>
{% endfor %}
```
2021-11-11 15:35:45 +01:00
René Kijewski
cfe83bcb73 Implement {{loop.cycle(…)}} similar to Jinja 2021-11-11 10:05:34 +01:00
Kelly Thomas Kline
c26d511fc0 Make test name consistent with test template name 2021-10-13 13:59:12 +02:00
Kelly Thomas Kline
c288f7fafa Initial test work 2021-10-13 13:59:12 +02:00