Author Topic: Roundcube 1.5 Beta - problems with template conditions  (Read 3234 times)

Offline chris_scott

  • Jr. Member
  • **
  • Posts: 12
Roundcube 1.5 Beta - problems with template conditions
« on: May 14, 2021, 07:57:25 AM »
Hi,
I'm having some problems with the skin template conditionals (if/elseif/else) in RC 1.5 Beta (latest as of this post.) In some circumstances the html code from ALL the if clauses is included, even if the conditions don't match. (See the attached screenshot.)

I'm pasting the code that works in RC 1.4 but doesn't work in RC 1.5. I have it added to header.html of a custom skin. The odd thing is that if I make the text in the if clauses shorter, it starts working properly. For example, if I remove the last two sentences inside the span of condition 4, it works.

Does anyone have any ideas what's going on?

Code: [Select]
<roundcube:if condition="env:task == 'mail' && env:action == 'show'" />
    Condition 1
    <span style="display:none">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse nulla quam, egestas
        posuere ac, tincidunt a purus. Ut ornare semper vehicula. Maecenas molestie laoreet elit. Suspendisse
        a accumsan ante, sit amet efficitur tellus. Nulla eget vehicula purus. Praesent gravida, nisl vitae
        egestas vestibulum, erat nulla eleifend leo, in feugiat quam elit vel nulla.
    </span>
<roundcube:elseif condition="env:task == 'mail' && env:action == 'compose'" />
    Condition 2
    <span style="display:none">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse nulla quam, egestas
        posuere ac, tincidunt a purus. Ut ornare semper vehicula. Maecenas molestie laoreet elit. Suspendisse
        a accumsan ante, sit amet efficitur tellus. Nulla eget vehicula purus. Praesent gravida, nisl vitae
        egestas vestibulum, erat nulla eleifend leo, in feugiat quam elit vel nulla.
    </span>
<roundcube:elseif condition="env:task == 'mail' && !env:action == 'plugin.summary'" />
    Condition 3
    <span style="display:none">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse nulla quam, egestas
        posuere ac, tincidunt a purus. Ut ornare semper vehicula. Maecenas molestie laoreet elit. Suspendisse
        a accumsan ante, sit amet efficitur tellus. Nulla eget vehicula purus. Praesent gravida, nisl vitae
        egestas vestibulum, erat nulla eleifend leo, in feugiat quam elit vel nulla.
    </span>
<roundcube:elseif condition="env:task == 'addressbook'" />
    Condition 4
    <span style="display:none">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse nulla quam, egestas
        posuere ac, tincidunt a purus. Ut ornare semper vehicula. Maecenas molestie laoreet elit. Suspendisse
        a accumsan ante, sit amet efficitur tellus. Nulla eget vehicula purus. Praesent gravida, nisl vitae
        egestas vestibulum, erat nulla eleifend leo, in feugiat quam elit vel nulla. Nam ullamcorper sapien purus,
        vitae sollicitudin enim lobortis eget. Aliquam interdum fermentum turpis nec ultrices.
    </span>
<roundcube:elseif condition="env:task == 'settings'" />
    Condition 5
    <span style="display:none">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse nulla quam, egestas
        posuere ac, tincidunt a purus. Ut ornare semper vehicula. Maecenas molestie laoreet elit. Suspendisse
        a accumsan ante, sit amet efficitur tellus. Nulla eget vehicula purus. Praesent gravida, nisl vitae
        egestas vestibulum, erat nulla eleifend leo, in feugiat quam elit vel nulla.
    </span>
<roundcube:else/>
    Condition 6
    <span style="display:none">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    </span>
<roundcube:endif />

Online alec

  • Hero Member
  • *****
  • Posts: 1,363
Re: Roundcube 1.5 Beta - problems with template conditions
« Reply #1 on: May 14, 2021, 09:54:25 AM »
It works for me in git-master. I put your template content at the end of skins/elastic/templates/mail.html and I get "Condition 3" only in the result.

Offline chris_scott

  • Jr. Member
  • **
  • Posts: 12
Re: Roundcube 1.5 Beta - problems with template conditions
« Reply #2 on: May 17, 2021, 03:35:25 AM »
Hi alec,
I downloaded and installed a fresh copy of RC 1.5 beta (apache/mysql) from git master (https://github.com/roundcube/roundcubemail) and added the code at the end of skins/elastic/templates/mail.html as you indicated. The result is still the same: all the conditions are rendered. (Please see the attachments.) I have not made any modifications to the RC code and the plugins array is empty--the installation is completely clean. I get the same result when I add the code to any other template files; the third screenshot shows the code added to elastic/templates/includes/layout.html; the fourth screenshot: larry/includes/header.html. Thank you for taking another look at this.

Online alec

  • Hero Member
  • *****
  • Posts: 1,363
Re: Roundcube 1.5 Beta - problems with template conditions
« Reply #3 on: May 17, 2021, 04:20:12 AM »
What PHP version? Try with Opcache disabled.

Offline chris_scott

  • Jr. Member
  • **
  • Posts: 12
Re: Roundcube 1.5 Beta - problems with template conditions
« Reply #4 on: May 17, 2021, 04:28:53 AM »
PHP Version 7.2.34-18+ubuntu20.04.1+deb.sury.org+1

OPcache disabled, no change: all the conditions are still rendered.

Offline chris_scott

  • Jr. Member
  • **
  • Posts: 12
Re: Roundcube 1.5 Beta - problems with template conditions
« Reply #5 on: May 17, 2021, 04:53:07 AM »
Take a look at this: if I delete some text from any of the conditions and make the entire conditional statement equal to or smaller than 2816 bytes, it starts working. If the statement is larger than 2816 bytes, it doesn't work. I can delete the text from any of the conditions to make it work, that's why I'm thinking that it has something to do with the size of the entire statement. I don't know if this helps.

To illustrate: if I delete the text highlighted in the screenshot (77 characters,) it works fine. Again, RC 1.4 doesn't have this problem.


Online alec

  • Hero Member
  • *****
  • Posts: 1,363
Re: Roundcube 1.5 Beta - problems with template conditions
« Reply #6 on: May 17, 2021, 05:33:45 AM »
Maybe that's a PHP issue. Works for me on 7.4 and 8.0.

Online alec

  • Hero Member
  • *****
  • Posts: 1,363
Re: Roundcube 1.5 Beta - problems with template conditions
« Reply #7 on: May 17, 2021, 06:00:23 AM »
You could also test with pcre.jit disabled.

Offline chris_scott

  • Jr. Member
  • **
  • Posts: 12
Re: Roundcube 1.5 Beta - problems with template conditions
« Reply #8 on: May 17, 2021, 09:59:27 AM »
Disabling pcre.jit on php 7.2 worked. I looked online and it looks like there are some reports of pcre.jit stack issues on php 7.2 and 7.3. I checked php 7.4 and php 8.0 and the conditions work properly there with pcre.jit enabled.

I'm concerned about this. We have skins with those kind of conditions running on a lot of servers and so far everything's been working fine on RC 1.4 and on all php versions. But obviously something in the RC code has changed between the versions 1.4 and 1.5 and now the skins won't work properly on php 7.2 and possibly on 7.3 as well. And we can't tell our customers to disable pcre.jit when their Roundcube stops working...

I'll check if the condition code can be shortened to make it work, but this isn't a sustainable solution; the operation of the conditions shouldn't depend on the length of their contents...

Would you mind looking in the RC code to see what might have changed in those regex searches that is now causing those issues? Thank you!


Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Re: Roundcube 1.5 Beta - problems with template conditions
« Reply #10 on: May 17, 2021, 02:19:21 PM »
1.5 supports nested If statements. Just out of curiosity, does using that kind of structure make any difference to the result?
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline chris_scott

  • Jr. Member
  • **
  • Posts: 12
Re: Roundcube 1.5 Beta - problems with template conditions
« Reply #11 on: May 17, 2021, 02:32:20 PM »
Yes, turning one of the elseifs into a nested if makes the entire structure work properly.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Re: Roundcube 1.5 Beta - problems with template conditions
« Reply #12 on: May 19, 2021, 02:46:45 AM »
Please give https://github.com/roundcube/roundcubemail/commit/bf2c4f32e495617135a6d4681866b66be8e52aed a try. It does not exactly solve the issue but it does increase the max size of the match, going from around 2750b to 8250b on my 7.2 test setup
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline chris_scott

  • Jr. Member
  • **
  • Posts: 12
Re: Roundcube 1.5 Beta - problems with template conditions
« Reply #13 on: May 19, 2021, 03:02:19 AM »
I tested the fix with the original code in our custom skin and it works properly, thank you! The "if" statement is 5068 bytes so it fits in the new 8250 byte limit. :)