Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: "default" Volt filter break the compilation if used in a switch case block #16003

Open
ChristopheMayet opened this issue Jun 30, 2022 · 1 comment
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report external dependency This issue depends on external issue to be resolved. status: medium Medium

Comments

@ChristopheMayet
Copy link

ChristopheMayet commented Jun 30, 2022

Hi 😃.

Describe the bug
In a switch control structure inside a Volt template, if I use default(…) native filter in code template, Volt compiler raises the following error:
Message: Uncaught Phalcon\Mvc\View\Exception: Syntax error, unexpected token DEFAULT(default) in …

To Reproduce
Write this template (views/bug.volt) :

{% set aNumber = 1 %}
{% switch aNumber %}
    {% case 0 %}
        {{ greatText }}
        {% break %}
    {% case 1 %}
        {{ false|default('simple text') }}
        {% break %}
{% endswitch %}

and compile it with the Volt engine compiler:

$compiler->compile("views/bug.volt");

Expected behavior
Compilation finish successfully, without any error.

Details

  • Phalcon version: 3.4.5
  • PHP Version: 7.3.33
  • Operating System: Linux Ubuntu 18.04.6
  • Installation type: via package manager (docker)

Additional context
I caught this by searching this specific issue, I came accross this fix, however I noticed that it only check if the "default" token is in a switch (means the default case of the switch), not if it's a valid filter in a case block.
I looked at the current state of master, and I think the issue is still there as the code is still nearly the same
Unfortunately I can't test a more recent version of the framework, but I'm confident about the bug still happens.

@ChristopheMayet ChristopheMayet added bug A bug report status: unverified Unverified labels Jun 30, 2022
@ChristopheMayet ChristopheMayet changed the title [BUG]: "default" Volt filter broken if used in a switch case block [BUG]: "default" Volt filter break the compilation if used in a switch case block Jun 30, 2022
@niden niden self-assigned this Jul 1, 2022
@niden niden added this to Working on it in Phalcon Roadmap Jul 1, 2022
@niden
Copy link
Sponsor Member

niden commented Jul 4, 2022

@Jeckerson This is a parser issue (for Volt).

{% switch condition %}
    {% case 1 %}
        Hello 1
        {% break %}
    {% case 2 %}
        Hello 2
        {% break %}
    {% default %}
        Hello {{ condition > 10 | default("ten") }}
{% endswitch %}

This produces the error reported.

@niden niden added status: medium Medium external dependency This issue depends on external issue to be resolved. 5.0 The issues we want to solve in the 5.0 release and removed status: unverified Unverified labels Jul 4, 2022
@niden niden moved this from Working on it to Backlog in Phalcon Roadmap Jul 4, 2022
@Jeckerson Jeckerson assigned Jeckerson and unassigned niden Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report external dependency This issue depends on external issue to be resolved. status: medium Medium
Projects
Status: Backlog
Phalcon Roadmap
  
Backlog
Development

No branches or pull requests

3 participants