Use Ructe #327

Merged
elegaanz merged 46 commits from ructe into master 6 years ago
elegaanz commented 6 years ago (Migrated from github.com)

All the template are now compiled at compile-time with the ructe crate.

I preferred to use it instead of askama because it allows more complex Rust expressions, where askama only supports a small subset of expressions and doesn't allow them everywhere (for instance, {{ macro!() | filter }} would result in a parsing error).

The diff is quite huge, but there is normally no changes in functionality.

Fixes #161 and unblocks #110 and #273

All the template are now compiled at compile-time with the `ructe` crate. I preferred to use it instead of askama because it allows more complex Rust expressions, where askama only supports a small subset of expressions and doesn't allow them everywhere (for instance, `{{ macro!() | filter }}` would result in a parsing error). The diff is quite huge, but there is normally no changes in functionality. Fixes #161 and unblocks #110 and #273
elegaanz commented 6 years ago (Migrated from github.com)

It also updates Rocket to 0.4 RC 1, and Rocket i18n to the latest commits (that I should push btw, I completely forgot 😅).

It also updates Rocket to 0.4 RC 1, and Rocket i18n to the latest commits (that I should push btw, I completely forgot :sweat_smile:).
trinity-1686a reviewed 6 years ago
Owner

I knew it would land to the pr x)

I knew it would land to the pr x)
elegaanz (Migrated from github.com) reviewed 6 years ago
elegaanz (Migrated from github.com) commented 6 years ago

Yes, I just remembered I forgot it. 😁

Yes, I just remembered I forgot it. :grin:
trinity-1686a reviewed 6 years ago
trinity-1686a left a comment
Owner

Whoa that's a lot of work. I didn't realize there would be that much changes in here.
This is good work, however I think this might have introduced some XSSs, so I'll have to put my veto for the time being. I'll check if I'm right when the compilation end on my side.

Whoa that's a lot of work. I didn't realize there would be that much changes in here. This is good work, however I think this might have introduced some XSSs, so I'll have to put my veto for the time being. I'll check if I'm right when the compilation end on my side.
Owner

I think we lost translation here, and I don't see it added neither on requires_login calls, nor in the template or the route

I think we lost translation here, and I don't see it added neither on `requires_login` calls, nor in the template or the route
Owner

As the return type is supposed to be html, maybe it should be something else (SafeString or Html), but we should make sure all user controlled parameters are properly escaped. Otherwise there could be an xss in the alt and title fields the user control, or in src a remote server could send

As the return type is supposed to be html, maybe it should be something else (SafeString or Html), but we should make sure all user controlled parameters are properly escaped. Otherwise there could be an xss in the `alt` and `title` fields the user control, or in `src` a remote server could send
Owner

you could use !self.display_name.is_empty() (at least it's what clippy would tell you)

you could use `!self.display_name.is_empty()` (at least it's what clippy would tell you)
@ -337,3 +335,3 @@
msgid_plural "{{ count }} articles in this blog"
msgid_plural "{0} articles in this blog"
msgstr[0] ""
msgstr[1] ""
Owner

I love how it changed from a very strange and long message to a very normal and short one

I love how it changed from a very strange and long message to a very normal and short one
@ -29,3 +30,3 @@
user_id: user.id,
value: random_hex(),
scopes: query.scopes,
scopes: query.scopes.clone(),
Owner

what is the .. in a query part for? I only know its use in the path part

what is the `..` in a query part for? I only know its use in the path part
Owner

It would feel more at it's place in src/template_utils.rs I think

It would feel more at it's place in `src/template_utils.rs` I think
Owner

ugh I did the same change on search, we will have some merge issues for literally nothing 😢 (and also in a lot of other places, but for good reasons)

ugh I did the same change on `search`, we will have some merge issues for literally nothing :cry: (and also in a lot of other places, but for good reasons)
@ -0,0 +44,4 @@
pub fn avatar(conn: &Connection, user: &User, size: Size, pad: bool, catalog: &Catalog) -> Html<String> {
let name = escape(&user.name(conn)).to_string();
Html(format!(
Owner

I haven't tested yet, but big warning on fields like title, one could maybe use a name containing html (or js) and get it unescaped in his page

I haven't tested yet, but big warning on fields like `title`, one could maybe use a name containing html (or js) and get it unescaped in his page
trinity-1686a reviewed 6 years ago
Owner

is it normal for {0} to be translated by {0}{1}{2}?

is it normal for `{0}` to be translated by `{0}{1}{2}`?
elegaanz (Migrated from github.com) reviewed 6 years ago
elegaanz (Migrated from github.com) commented 6 years ago

You are right, I forgot to call it from the routes (I preferred to change this behavior to avoid having to depend on rocket_i18n in plume-common, and to have an extra Catalog parameter).

You are right, I forgot to call it from the routes (I preferred to change this behavior to avoid having to depend on rocket_i18n in plume-common, and to have an extra `Catalog` parameter).
trinity-1686a reviewed 6 years ago
@ -0,0 +12,4 @@
<p>@article.subtitle</p>
</main>
<p class="author">
@Html(i18n!(ctx.1, "By {0}"; format!(
Owner

there is an xss injection there, because {0} is not properly escaped. Example paylod: display name = "><script>alert("xss");</script> <div title="

there is an xss injection there, because {0} is not properly escaped. Example paylod: display name = `"><script>alert("xss");</script> <div title="`
trinity-1686a reviewed 6 years ago
@ -0,0 +44,4 @@
pub fn avatar(conn: &Connection, user: &User, size: Size, pad: bool, catalog: &Catalog) -> Html<String> {
let name = escape(&user.name(conn)).to_string();
Html(format!(
Owner

I was right on this one "><script>alert("xss");</script> <div title=" as a display name trigger it

I was right on this one `"><script>alert("xss");</script> <div title="` as a display name trigger it
elegaanz (Migrated from github.com) reviewed 6 years ago
@ -29,3 +30,3 @@
user_id: user.id,
value: random_hex(),
scopes: query.scopes,
scopes: query.scopes.clone(),
elegaanz (Migrated from github.com) commented 6 years ago

It is the new way to handle queries in Rocket 0.4. The new syntax is:

  • /?<x> is a single query argument (?x=foo)
  • You can separate query arguments with & (/?<x>&<y> will match ?x=foo&y=bar)
  • If you want to deserialize a whole struct, you have to use .. and each of its field will be a query argument (I think it was the default behavior in 0.3)
It is the new way to handle queries in Rocket 0.4. The new syntax is: - `/?<x>` is a single query argument (`?x=foo`) - You can separate query arguments with `&` (`/?<x>&<y>` will match `?x=foo&y=bar`) - If you want to deserialize a whole struct, you have to use `..` and each of its field will be a query argument (I think it was the default behavior in 0.3)
elegaanz (Migrated from github.com) reviewed 6 years ago
elegaanz (Migrated from github.com) commented 6 years ago

No, it is a translation I forgot to update I think.

No, it is a translation I forgot to update I think.
elegaanz (Migrated from github.com) reviewed 6 years ago
@ -0,0 +12,4 @@
<p>@article.subtitle</p>
</main>
<p class="author">
@Html(i18n!(ctx.1, "By {0}"; format!(
elegaanz (Migrated from github.com) commented 6 years ago

Yes, I guess we could use .to_html from Ructe to escape it https://github.com/kaj/ructe/blob/master/src/template_utils.rs#L24

Yes, I guess we could use `.to_html` from Ructe to escape it https://github.com/kaj/ructe/blob/master/src/template_utils.rs#L24
trinity-1686a reviewed 6 years ago
Owner

The same payload is also working, however as this is only used on private pages, this has less impact (one can only harm themselves)

The same payload is also working, however as this is only used on private pages, this has less impact (one can only harm themselves)
trinity-1686a reviewed 6 years ago
@ -0,0 +12,4 @@
<p>@article.subtitle</p>
</main>
<p class="author">
@Html(i18n!(ctx.1, "By {0}"; format!(
Owner

then it should be called only on L18, as to not break the link we build

then it should be called only on L18, as to not break the link we build
elegaanz (Migrated from github.com) reviewed 6 years ago
@ -0,0 +12,4 @@
<p>@article.subtitle</p>
</main>
<p class="author">
@Html(i18n!(ctx.1, "By {0}"; format!(
elegaanz (Migrated from github.com) commented 6 years ago

Would doing that break anything?

i18n!(ctx.1, "By {0}"; format!(
    "<a href=\"/@/{}/\">{}</a>",
    article.get_authors(ctx.0)[0].get_fqn(ctx.0).to_html(),
    article.get_authors(ctx.0)[0].name(ctx.0).to_html()
))
Would doing that break anything? ```rust i18n!(ctx.1, "By {0}"; format!( "<a href=\"/@/{}/\">{}</a>", article.get_authors(ctx.0)[0].get_fqn(ctx.0).to_html(), article.get_authors(ctx.0)[0].name(ctx.0).to_html() )) ```
trinity-1686a reviewed 6 years ago
@ -0,0 +12,4 @@
<p>@article.subtitle</p>
</main>
<p class="author">
@Html(i18n!(ctx.1, "By {0}"; format!(
Owner

it would prevent an xss, but I think a simple " as user name could break the layout (you can test it by yourself)

it would prevent an xss, but I think a simple `"` as user name could break the layout (you can test it by yourself)
trinity-1686a reviewed 6 years ago
@ -0,0 +12,4 @@
<p>@article.subtitle</p>
</main>
<p class="author">
@Html(i18n!(ctx.1, "By {0}"; format!(
Owner

to_html seems to be only to include content in the html tree, not inside tags

`to_html` seems to be only to include content in the html tree, not inside tags
trinity-1686a reviewed 6 years ago
@ -29,3 +30,3 @@
user_id: user.id,
value: random_hex(),
scopes: query.scopes,
scopes: query.scopes.clone(),
Owner

how ok, I didn't know, and I prefer it a lot to the old way

how ok, I didn't know, and I prefer it a lot to the old way
codecov[bot] commented 6 years ago (Migrated from github.com)

Codecov Report

Merging #327 into master will increase coverage by 1.26%.
The diff coverage is 1.62%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #327      +/-   ##
==========================================
+ Coverage   28.62%   29.88%   +1.26%     
==========================================
  Files          61       62       +1     
  Lines        6471     6320     -151     
==========================================
+ Hits         1852     1889      +37     
+ Misses       4619     4431     -188
Impacted Files Coverage Δ
plume-models/src/lib.rs 89.9% <ø> (-1.4%) ⬇️
src/routes/posts.rs 0% <0%> (ø) ⬆️
src/routes/comments.rs 0% <0%> (ø) ⬆️
src/routes/likes.rs 0% <0%> (ø) ⬆️
src/routes/medias.rs 0% <0%> (ø) ⬆️
src/template_utils.rs 0% <0%> (ø)
src/routes/user.rs 0% <0%> (ø) ⬆️
plume-models/src/posts.rs 9.81% <0%> (+0.07%) ⬆️
src/main.rs 0% <0%> (ø) ⬆️
plume-common/src/utils.rs 90.75% <0%> (ø) ⬆️
... and 40 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ff3b65...e25081c. Read the comment docs.

# [Codecov](https://codecov.io/gh/Plume-org/Plume/pull/327?src=pr&el=h1) Report > Merging [#327](https://codecov.io/gh/Plume-org/Plume/pull/327?src=pr&el=desc) into [master](https://codecov.io/gh/Plume-org/Plume/commit/5ff3b65cc59ed8826bb10501e09693145216b2a9?src=pr&el=desc) will **increase** coverage by `1.26%`. > The diff coverage is `1.62%`. [![Impacted file tree graph](https://codecov.io/gh/Plume-org/Plume/pull/327/graphs/tree.svg?width=650&token=sHtxmDuZ06&height=150&src=pr)](https://codecov.io/gh/Plume-org/Plume/pull/327?src=pr&el=tree) ```diff @@ Coverage Diff @@ ## master #327 +/- ## ========================================== + Coverage 28.62% 29.88% +1.26% ========================================== Files 61 62 +1 Lines 6471 6320 -151 ========================================== + Hits 1852 1889 +37 + Misses 4619 4431 -188 ``` | [Impacted Files](https://codecov.io/gh/Plume-org/Plume/pull/327?src=pr&el=tree) | Coverage Δ | | |---|---|---| | [plume-models/src/lib.rs](https://codecov.io/gh/Plume-org/Plume/pull/327/diff?src=pr&el=tree#diff-cGx1bWUtbW9kZWxzL3NyYy9saWIucnM=) | `89.9% <ø> (-1.4%)` | :arrow_down: | | [src/routes/posts.rs](https://codecov.io/gh/Plume-org/Plume/pull/327/diff?src=pr&el=tree#diff-c3JjL3JvdXRlcy9wb3N0cy5ycw==) | `0% <0%> (ø)` | :arrow_up: | | [src/routes/comments.rs](https://codecov.io/gh/Plume-org/Plume/pull/327/diff?src=pr&el=tree#diff-c3JjL3JvdXRlcy9jb21tZW50cy5ycw==) | `0% <0%> (ø)` | :arrow_up: | | [src/routes/likes.rs](https://codecov.io/gh/Plume-org/Plume/pull/327/diff?src=pr&el=tree#diff-c3JjL3JvdXRlcy9saWtlcy5ycw==) | `0% <0%> (ø)` | :arrow_up: | | [src/routes/medias.rs](https://codecov.io/gh/Plume-org/Plume/pull/327/diff?src=pr&el=tree#diff-c3JjL3JvdXRlcy9tZWRpYXMucnM=) | `0% <0%> (ø)` | :arrow_up: | | [src/template\_utils.rs](https://codecov.io/gh/Plume-org/Plume/pull/327/diff?src=pr&el=tree#diff-c3JjL3RlbXBsYXRlX3V0aWxzLnJz) | `0% <0%> (ø)` | | | [src/routes/user.rs](https://codecov.io/gh/Plume-org/Plume/pull/327/diff?src=pr&el=tree#diff-c3JjL3JvdXRlcy91c2VyLnJz) | `0% <0%> (ø)` | :arrow_up: | | [plume-models/src/posts.rs](https://codecov.io/gh/Plume-org/Plume/pull/327/diff?src=pr&el=tree#diff-cGx1bWUtbW9kZWxzL3NyYy9wb3N0cy5ycw==) | `9.81% <0%> (+0.07%)` | :arrow_up: | | [src/main.rs](https://codecov.io/gh/Plume-org/Plume/pull/327/diff?src=pr&el=tree#diff-c3JjL21haW4ucnM=) | `0% <0%> (ø)` | :arrow_up: | | [plume-common/src/utils.rs](https://codecov.io/gh/Plume-org/Plume/pull/327/diff?src=pr&el=tree#diff-cGx1bWUtY29tbW9uL3NyYy91dGlscy5ycw==) | `90.75% <0%> (ø)` | :arrow_up: | | ... and [40 more](https://codecov.io/gh/Plume-org/Plume/pull/327/diff?src=pr&el=tree-more) | | ------ [Continue to review full report at Codecov](https://codecov.io/gh/Plume-org/Plume/pull/327?src=pr&el=continue). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta) > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://codecov.io/gh/Plume-org/Plume/pull/327?src=pr&el=footer). Last update [5ff3b65...e25081c](https://codecov.io/gh/Plume-org/Plume/pull/327?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
trinity-1686a reviewed 6 years ago
Owner

I totally understand your thought, it will be more logical to do so

I totally understand your thought, it will be more logical to do so
trinity-1686a reviewed 6 years ago
Owner

and again x)

and again x)
trinity-1686a reviewed 6 years ago
Owner

The attribute to use is action, not href (this issue was introduced on Tera)

                    <form class="inline" method="post" action="/admin/users/@user.id/ban">
The attribute to use is action, not href (this issue was introduced on Tera) ```suggestion <form class="inline" method="post" action="/admin/users/@user.id/ban"> ```
trinity-1686a reviewed 6 years ago
trinity-1686a left a comment
Owner

I haven't finished yet, but I will post it now so you can start working on it if you have time

I haven't finished yet, but I will post it now so you can start working on it if you have time
Owner

this is not supposed to be committed, you git added to much after checking off from search (same is true for other files of the directory)

this is not supposed to be committed, you `git add`ed to much after checking off from search (same is true for other files of the directory)
Owner

there is an xss reflection here (someone can inject script, but only to themselves, or at least I think). An example payload is trying to log in as "><script>alert("xss")</script><a href=" with an invalid password

there is an xss reflection here (someone can inject script, but only to themselves, or at least I think). An example payload is trying to log in as `"><script>alert("xss")</script><a href="` with an invalid password
@ -0,0 +53,4 @@
></div>"#,
size = size.as_str(),
padded = if pad { "padded" } else { "" },
url = user.avatar_url(conn),
Owner

avatar url for remote user is currently unverified, a rogue server could maybe try to inject something through there

avatar url for remote user is currently unverified, a rogue server could maybe try to inject something through there
@ -0,0 +62,4 @@
let mut res = String::from(r#"<div class="tabs">"#);
for (url, title, selected) in links {
res.push_str(r#"<a href=""#);
res.push_str(url);
Owner

in case of a user name (as in the @ they gave at signup) like "><script>alert("xss")</script><a href=", the url can contain dangerous content. However I think user name should not contains any characters from the set "<>&, in which case there is no injection possible. So I'd argue even if the xss appear here, the real fix will be to validate user name at registration

in case of a user name (as in the @ they gave at signup) like `"><script>alert("xss")</script><a href="`, the url can contain dangerous content. However I think user name should not contains any characters from the set `"<>&`, in which case there is no injection possible. So I'd argue even if the xss appear here, the real fix will be to validate user name at registration
Owner

The author.name is not interpreted

            <a class="author" href="/@@/@author.get_fqn(ctx.0)">@author.name(ctx.0)</a>
The author.name is not interpreted ```suggestion <a class="author" href="/@@/@author.get_fqn(ctx.0)">@author.name(ctx.0)</a> ```
@ -0,0 +30,4 @@
<p>@i18n!(ctx.1, "No posts to see here yet.")</p>
}
@if is_author {
<a href="/~/@fqn/new/" class="button inline-block">@i18n!(ctx.1, "New article")</a>
Owner

I'm not sure why yet, but having a user&display name of " content= shift the button to the left

I'm not sure why yet, but having a user&display name of `" content=` shift the button to the left
@ -0,0 +4,4 @@
@(ctx: BaseContext, error_message: &str, error: Content)
@:base_template(ctx, error_message, {}, {}, {
@:error()
Owner

I don't see the definition of this macro/function, could you tell me where it is?

I don't see the definition of this macro/function, could you tell me where it is?
Owner

Wouldn't it be better to have one "long" string to translate, in which we inject format!("</p><em>{}</em><p>", n_users)? I can imagine in some languages it's more accurate to say something where "people" goes first and "home to" second

Wouldn't it be better to have one "long" string to translate, in which we inject `format!("</p><em>{}</em><p>", n_users)`? I can imagine in some languages it's more accurate to say something where "people" goes first and "home to" second
Owner

You can do without format (not sure if it's better though)

              <p><a href="/@@/@admin.get_fqn(ctx.0)">@admin.name(ctx.0)</a><small>@@@admin.get_fqn(ctx.0)</small></p>
You can do without `format` (not sure if it's better though) ```suggestion <p><a href="/@@/@admin.get_fqn(ctx.0)">@admin.name(ctx.0)</a><small>@@@admin.get_fqn(ctx.0)</small></p> ```
Owner

this button should not be here if MediaCategory != Image
(was true for Tera too though)

this button should not be here if MediaCategory != Image (was true for Tera too though)
Owner

same about translating with a single string

same about translating with a single string
@ -0,0 +5,4 @@
<div class="card">
@if article.cover_id.is_some() {
<div class="cover" style="background-image: url('@Html(article.cover_url(ctx.0).unwrap_or_default())')"></div>
Owner

a rogue server could have sent us an invalid url containing dangerous content. Not sure if it's really an attack vector yet, but this might very well be

a rogue server could have sent us an invalid url containing dangerous content. Not sure if it's really an attack vector yet, but this might very well be
@ -0,0 +104,4 @@
<p aria-label="@i18n!(ctx.1, "One like", "{0} likes", &n_likes)" title="@i18n!(ctx.1, "One like", "{0} likes", n_likes)">
@n_likes
</p>
<a href="/login?m=Login%20to%20like" class="action">@icon!("heart") @i18n!(ctx.1, "Add yours")</a>
Owner

Message won't get translated

Message won't get translated
@ -0,0 +111,4 @@
<p aria-label="@i18n!(ctx.1, "One boost", "{0} boost", &n_reshares)" title="@i18n!(ctx.1, "One boost", "{0} boosts", n_reshares)">
@n_reshares
</p>
<a href="/login?m=Login%20to%20boost" class="action">@icon!("repeat") @i18n!(ctx.1, "Boost")</a>
Owner

Message won't get translated

Message won't get translated
trinity-1686a reviewed 6 years ago
trinity-1686a left a comment
Owner

I have to say I prefer partial templates included in other templates over functions returning an Html<String>, because in the latter case ructe will consider all as trusted, whereas with partial template it will try to escape as much as it can

I have to say I prefer partial templates included in other templates over functions returning an `Html<String>`, because in the latter case ructe will consider all as trusted, whereas with partial template it will try to escape as much as it can
@ -0,0 +9,4 @@
@:header(ctx, &user, follows, is_remote, remote_url)
@tabs(&[
(&format!("/@/{}", user.get_fqn(ctx.0)), i18n!(ctx.1, "Articles"), true),
Owner

user fqn can't be assumed to be trusted yet, one can inject content by this way

user fqn can't be assumed to be trusted yet, one can inject content by this way
@ -0,0 +8,4 @@
@:header(ctx, &user, follows, is_remote, remote_url)
@tabs(&[
(&format!("/@/{}", user.get_fqn(ctx.0)), i18n!(ctx.1, "Articles"), false),
Owner

same here, user fqn can't be trusted yet

same here, user fqn can't be trusted yet
trinity-1686a reviewed 6 years ago
@ -0,0 +62,4 @@
let mut res = String::from(r#"<div class="tabs">"#);
for (url, title, selected) in links {
res.push_str(r#"<a href=""#);
res.push_str(url);
Owner

fixed by 9714bafded

fixed by 9714bafded2aefeaf2eb4123a338b93c4cd019d8
trinity-1686a reviewed 6 years ago
@ -0,0 +30,4 @@
<p>@i18n!(ctx.1, "No posts to see here yet.")</p>
}
@if is_author {
<a href="/~/@fqn/new/" class="button inline-block">@i18n!(ctx.1, "New article")</a>
Owner

this was only on user name (fqn), fixed by 9714bafded then

this was only on user name (fqn), fixed by 9714bafded2aefeaf2eb4123a338b93c4cd019d8 then
trinity-1686a reviewed 6 years ago
@ -0,0 +9,4 @@
@:header(ctx, &user, follows, is_remote, remote_url)
@tabs(&[
(&format!("/@/{}", user.get_fqn(ctx.0)), i18n!(ctx.1, "Articles"), true),
Owner

fixed by 9714bafded

fixed by 9714bafded2aefeaf2eb4123a338b93c4cd019d8
trinity-1686a reviewed 6 years ago
@ -0,0 +8,4 @@
@:header(ctx, &user, follows, is_remote, remote_url)
@tabs(&[
(&format!("/@/{}", user.get_fqn(ctx.0)), i18n!(ctx.1, "Articles"), false),
Owner

fixed by 9714bafded

fixed by 9714bafded2aefeaf2eb4123a338b93c4cd019d8
trinity-1686a reviewed 6 years ago
@ -0,0 +104,4 @@
<p aria-label="@i18n!(ctx.1, "One like", "{0} likes", &n_likes)" title="@i18n!(ctx.1, "One like", "{0} likes", n_likes)">
@n_likes
</p>
<a href="/login?m=Login%20to%20like" class="action">@icon!("heart") @i18n!(ctx.1, "Add yours")</a>
Owner

actually as there are route for it, and has_liked and has_reshared are both set to false by default, the whole @if ctx.2.is_some() {} else {} could be turned into a single branch. That way there is less code and it work better. The only issue is there would be no csrf token (no session cookie so rocket_csrf don't issue a token), so the user would be faced with an invalid csrf page. I should probably make rocket_csrf accept request with no cookie, not only response. Anyway it make no sens to do a csrf attack on a client having no session. And this would also remove most exceptions we set in main

Edit: I've added the functionality to latest rocket_csrf/master

actually as there are route for it, and has_liked and has_reshared are both set to false by default, the whole `@if ctx.2.is_some() {} else {}` could be turned into a single branch. That way there is less code and it work better. The only issue is there would be no csrf token (no session cookie so rocket_csrf don't issue a token), so the user would be faced with an invalid csrf page. I should probably make rocket_csrf accept request with no cookie, not only response. Anyway it make no sens to do a csrf attack on a client having no session. And this would also remove most exceptions we set in main Edit: I've added the functionality to latest rocket_csrf/master
igalic (Migrated from github.com) reviewed 6 years ago
igalic (Migrated from github.com) left a comment

use more raw strings!

use more raw strings!
igalic (Migrated from github.com) commented 6 years ago

maybe use

r#"<img="{}" alt="{}" title="{}" class="preview">#"

so you don't have to keep escaping the inner "

maybe use ```rust r#"<img="{}" alt="{}" title="{}" class="preview">#" ``` so you don't have to keep escaping the inner `"`
trinity-1686a reviewed 6 years ago
@ -0,0 +5,4 @@
<div class="card">
@if article.cover_id.is_some() {
<div class="cover" style="background-image: url('@Html(article.cover_url(ctx.0).unwrap_or_default())')"></div>
Owner

Fixed by ed71d24fe9

Fixed by ed71d24fe9bb66244474c87959c07dd422baeb14
trinity-1686a reviewed 6 years ago
@ -0,0 +53,4 @@
></div>"#,
size = size.as_str(),
padded = if pad { "padded" } else { "" },
url = user.avatar_url(conn),
Owner

fixed by ed71d24fe9

fixed by ed71d24fe9bb66244474c87959c07dd422baeb14
trinity-1686a reviewed 6 years ago
Owner

@igalic because I always do this mistake, warning on the end of your string, the correct syntax is r#"some content"#

@igalic because I always do this mistake, warning on the end of your string, the correct syntax is `r#"some content"#`
elegaanz (Migrated from github.com) reviewed 6 years ago
@ -0,0 +4,4 @@
@(ctx: BaseContext, error_message: &str, error: Content)
@:base_template(ctx, error_message, {}, {}, {
@:error()
elegaanz (Migrated from github.com) commented 6 years ago

It comes from the error parameter of this template. The Content type is a special type used by Ructe to pass template fragments to functions. Then, to inherit a template, you can call it (as we are doing with @:base_template here) and give it fragments of templates to be included as arguments between {}.

It comes from the `error` parameter of this template. The `Content` type is a special type used by Ructe to pass template fragments to functions. Then, to inherit a template, you can call it (as we are doing with `@:base_template` here) and give it fragments of templates to be included as arguments between `{}`.
trinity-1686a reviewed 6 years ago
@ -0,0 +4,4 @@
@(ctx: BaseContext, error_message: &str, error: Content)
@:base_template(ctx, error_message, {}, {}, {
@:error()
Owner

How ok I through it was a function call when it's more of a "insert the content of this var here". It's the same syntax as in templates/base.rs.html where it didn't bother me x)

How ok I through it was a function call when it's more of a "insert the content of this var here". It's the same syntax as in `templates/base.rs.html` where it didn't bother me x)
trinity-1686a reviewed 6 years ago
Owner

I think this is easier for translators to add new languages in here than it is to edit main.rs. Maybe include_i18! should read this file instead of getting languages from a static parameter (actually it could accept both), what do you think @BaptisteGelez ?

I think this is easier for translators to add new languages in here than it is to edit main.rs. Maybe include_i18! should read this file instead of getting languages from a static parameter (actually it could accept both), what do you think @BaptisteGelez ?
elegaanz (Migrated from github.com) reviewed 6 years ago
elegaanz (Migrated from github.com) commented 6 years ago

Ideally, I think include_i18n! should read all the .mo files in translations if no language list is provided. This way new languages would be loaded automatically, without needing to add them anywhere.

Ideally, I think include_i18n! should read all the .mo files in `translations` if no language list is provided. This way new languages would be loaded automatically, without needing to add them anywhere.
trinity-1686a reviewed 6 years ago
Owner

this would be perfect, however I'm not sure this can be done with macros. Still I'll try to do it

this would be perfect, however I'm not sure this can be done with macros. Still I'll try to do it
trinity-1686a reviewed 6 years ago
Owner

It seems like it's not possible to ls with normal macros, however it exist crates doing more or less what we want here (we could also use it to embed wasm files later on) and there

It seems like it's not possible to `ls` with normal macros, however it exist crates doing more or less what we want [here](https://github.com/pyros2097/rust-embed) (we could also use it to embed wasm files later on) and [there](https://github.com/Michael-F-Bryan/include_dir)
trinity-1686a reviewed 6 years ago
Owner

I think using any of those isn't in the range of this pr anyway, a macro is a thing, a dependency is another

I think using any of those isn't in the range of this pr anyway, a macro is a thing, a dependency is another
trinity-1686a reviewed 6 years ago
Owner

you forgot to add it to include_i18n

you forgot to add it to include_i18n
trinity-1686a approved these changes 6 years ago

Reviewers

trinity-1686a approved these changes 6 years ago
The pull request has been merged as 70af57c6e1.
You can also view command line instructions.

Step 1:

From your project repository, check out a new branch and test the changes.
git checkout -b ructe master
git pull origin ructe

Step 2:

Merge the changes and update on Forgejo.
git checkout master
git merge --no-ff ructe
git push origin master
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Plume/Plume#327
Loading…
There is no content yet.