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 when using triple starting braces. #896

Open
sanketdhoble opened this issue Jul 31, 2024 · 4 comments
Open

Bug when using triple starting braces. #896

sanketdhoble opened this issue Jul 31, 2024 · 4 comments

Comments

@sanketdhoble
Copy link

sanketdhoble commented Jul 31, 2024

For the below invalid syntax with triple brackets:
"Hey {{{data.variables.aa | default('there') }}"

data = { variables: {} }

I get output as [object][object] instead of getting syntax error. Why twig didn't throw it as an invalid syntax?

FYI: for input with starting & closing 3 braces : "Hey {{{data.variables.aa | default('there') }}}" I get output: "Hey [object][object]}"

Since I mistakenly added 3 braces, I expect to get an error instead of [object][object]

I used template.tokens to catch any twig syntax errors, but that didn't catch above error:

try {
    const template: any = Twig.twig({ data: startingString });
    if (template) {
        return template.tokens;
    }
} catch (err) {
    this.logger.error('Invalid twig syntax', startingString, err);
}

Any thoughts?

@willrowe
Copy link
Collaborator

willrowe commented Aug 2, 2024

It's most likely interpreting it as a map, which is an object in JavaScript. What happens if you use that same template in Twig PHP?

@ericmorand
Copy link
Contributor

@willrowe, I just tested and TwigPHP throws a syntax error:

Unexpected "}" in "index.twig" at line 1.

Using twing, which is more accurate than TwingPHP, we get a the same error, alongside the column where the parsing failed:

Unexpected "}" in "index.twig" at line 1, column 46.

This is interesting because at column 46, there is the last closing "}". We would need to investigate the TwigPHP / Twing parsers to understand why this column is the one where the error is detected.

@sanketdhoble
Copy link
Author

Any update on this?

@willrowe
Copy link
Collaborator

willrowe commented Aug 14, 2024

@sanketdhoble if you would like to look into this and draft up a PR then we will take a look. This project is completely open source and core developers only work on it when they have extra time to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants