389 Commits

Author SHA1 Message Date
René Kijewski
268d8250fb Use "target()" to parse "when" block
`target()` as used in parsing "let" and "if let" implements parsing
nested tuples and structs. But it does not implement parsing literals.

The functions `match_variant()` and `with_parameters()` as used in
parsing "when" blocks do not implement parsing nested structs, but it
implements parsing literals.

This PR combines `match_variant()` and `with_parameters()` into
`target()`, so that all `{%when%}` support nested structs, too.
2021-07-30 11:45:56 +02:00
René Kijewski
1622df7aee Allow omitting "with" keyword in match blocks
Askama uses the syntax `{% when Variant with (parameters) %}` in
`{% match %}` blocks. This is done because Askama does not implement the
whole pattern matching of Rust's `match` statements.

This PR wants to bring Askama a step closer Rust's matching, so the
"with" keyword should not be needed anymore.
2021-07-30 11:45:56 +02:00
René Kijewski
9e7fe8f2f9 Allow using "with" keyword in "let" statements
Askama uses the syntax `{% when Variant with (parameters) %}` in
`{% match %}` blocks.

This change allows the optional use of the keyword "with" in "let" and
"if let" statements, too.
2021-07-30 11:45:56 +02:00
René Kijewski
7e227907fe Implement destructoring of structs
This PR implements the destructoring of structs on the lhs of "let" and
"for" statements.
2021-07-05 14:17:49 +02:00
René Kijewski
3055c4b521 Add "destructoring tuple in loop" test 2021-07-05 13:48:41 +02:00
René Kijewski
44c0623a58 Add tuple destructoring tests 2021-07-05 13:48:41 +02:00
René Kijewski
20a5f7af7b Add loop variable shadowing test 2021-07-05 10:34:20 +02:00
René Kijewski
e9badca257 Replace rust_macro test to work on nightly
The current rust_test uses `stringify!()`. The documentation gives us
the warning:

> Note that the expanded results of the input tokens may change in the
> future. You should be careful if you rely on the output.

In the current nightly rust the result was indeed changed, so the test
not fails.

This PR replaces the test with another macro, that does not depend on
`stringify!()`.

Closes issue #504.
2021-07-02 16:37:11 +02:00
René Kijewski
c31fe5f3fc Fix expected error message for missing file
rust-lang/rust#82069 made error message that stem macro invocations more
verbose. Since Rust 1.54 (currently in beta) the message includes the
name of the offending macro.

This PR uses version_check to select the appropriate expected error
message.
2021-07-02 16:12:42 +02:00
René Kijewski
83b03cd485 Add "if let" tests 2021-07-01 10:24:32 +02:00
vallentin
017b5901fb Added loop tests 2021-06-23 21:34:17 +02:00
Ryan Kelly
49252d2457 Fix code generation for macro calls that store args in variables. 2021-06-22 11:41:45 +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
Dirkjan Ochtman
46792fe843 Rename test types to PascalCase 2021-03-30 09:59:12 +02:00
vallentin
7b954cd788 Added path and ext tests 2021-03-10 13:09:56 +01:00
vallentin
bfeaf5d6d8 Added option test 2021-02-22 13:50:09 +01:00
vallentin
7609f00c4b Added range test case 2021-02-22 13:05:44 +01:00
vallentin
000aff4a18 Added constants test 2021-01-13 08:58:49 +01:00
vallentin
f9db4446d5 Added copy literals related test case 2021-01-05 16:17:14 +01:00
vallentin
b76f7ef778 Removed implicit borrowing of literals, calls, and more (fixes #404) 2021-01-05 16:17:14 +01:00
vallentin
20f34be742 Added let shadow test 2020-12-25 22:42:44 +01:00
vallentin
6615d125bb Added more loop tests 2020-12-16 09:08:12 +01:00
Christian Vallentin
3b57663b5b
Fixed whitespace issue when generating match (#399)
* Fixed #397

* Updated parser to ignore whitespace between match and when

* Updated test cases

* Updated Python script to generate match ws tests

* Added match ws tests

* Resolved rustfmt lint
2020-12-12 18:01:22 +01:00
Christian Vallentin
5b01e60591
Fixed whitespace issue when generating if statement (#394)
* Fixed #377
2020-12-03 21:48:14 +01:00
Christian Vallentin
810d5ad506
Allow paths to start with :: (#393) 2020-12-02 20:46:29 +01:00
Christian Vallentin
a199defeca
Improved if statement generation to avoid issues with implicit borrows (#392)
* Changed to automatically coerce to bool

* Added new test case

* Updated test case to include else if
2020-12-01 17:01:05 +01:00
Christian Vallentin
f4065b09b9
Fixed implicit borrow of expressions (#390) 2020-12-01 09:25:36 +01:00
msrd0
f23162a208
Use syn::Error::to_compile_error and add trybuild ui test (#374) 2020-11-02 17:11:53 +01:00
Yuxuan Shui
121212bf29 Add integration tests for into_{f64,isize}
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2020-09-16 11:49:16 +02:00
Dirkjan Ochtman
b69879eefe Fix additional clippy issue 2020-07-20 11:21:32 +02:00
Dirkjan Ochtman
40748eb8e0 Clean up clippy issues 2020-07-20 11:07:24 +02:00
Andrew Dona-Couch
42c4cb1d87 Add fmt filter that swaps the first two arguments to format!().
This allows a more natural filter usage: `{{ val | fmt("{:?}") }}`
as well as enabling convenient filter composition:
`{{ price | to_f64 | fmt("${:.2}") | center }}`
2020-07-14 20:48:15 +02:00
Ciprian Dorin Craciun
af2fd0b8dc Add tests for allow whitespaces patch 2020-06-30 14:12:50 +02:00
Dirkjan Ochtman
4633dd989c Fix taking references of function arguments (fixes #311) 2020-04-23 13:40:39 +02:00
Nathan Lapel
3f202b32f2 Fixed clippy warnings 2020-03-18 22:33:51 +01:00
Nathan Lapel
5e1a7384e4 Use _visit_args in var/path calls 2020-03-18 22:33:51 +01:00
Nathan Lapel
520c5d7d5f Support function calls 2020-03-18 22:33:51 +01:00
Bjørn Madsen
91c2bbf804 Add support for warp 2020-01-29 11:22:47 +01:00
Dirkjan Ochtman
ff24eef1ff Move Iron integration into a separate askama_iron crate 2020-01-29 09:25:59 +01:00
Dirkjan Ochtman
75f32d3967 Move Gotham integration into separate askama_gotham crate 2020-01-29 09:25:59 +01:00
Dirkjan Ochtman
c6f9a053c7 Move Rocket integration into askama_rocket crate 2020-01-29 09:25:59 +01:00
Dirkjan Ochtman
b56c11639f Move Actix-Web integration into separate askama_actix crate 2020-01-29 09:25:59 +01:00
Dirkjan Ochtman
0f90ab83d6 Improve spacing 2020-01-12 16:07:35 +01:00
Dirkjan Ochtman
5c4896acf4 Add test for let declarations in blocks 2020-01-12 16:06:42 +01:00
Dirkjan Ochtman
8cc20486c7 Write conditional blocks before popping variable stack (see #227) 2020-01-12 15:44:49 +01:00
Tuomas Siipola
80148aa753 Support escaping in string literals
Do not attempt to parse escape sequences thoroughly. Instead let the
Rust compiler to check the string literals and provide nice error
messages if necessary.
2020-01-12 08:15:04 +01:00
DCjanus
6b11df9e92 upgrade dependencies(actix-web 0.7 -> 2) 2020-01-11 17:43:55 +01:00
Tuomas Siipola
cef055108d Support char literals 2020-01-03 19:56:18 +01:00
Dirkjan Ochtman
ea2034e806 Clean up clippy warnings 2020-01-02 22:58:13 +01:00
Dirkjan Ochtman
ebf99e6628 Fix formatting with cargo fmt 2019-11-04 14:00:26 +01:00