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

Curly braces in a conditional with a regex throws parsing error #29

Closed
litzinger opened this Issue Nov 29, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@litzinger
Copy link
Contributor

litzinger commented Nov 29, 2018

Description of the problem
Using curly braces in a regex comparison in a conditional causes a parsing error. I have a situation where I need to detect if a segment is a valid ISO code, e.g. en-us, or ca-fr. It appears as if the conditional parser is choking on the curly braces in the regex, b/c as soon as they are removed the error message goes away, but of course the regex isn't matching what I need it to match.

How To Reproduce
Steps to reproduce the behavior:
Add the following to a template file, and it'll yield the error message below.
{if segment_2 ~ "/\S{2}-\S{2}/"}{/if}

Error Messages


You have an invalid conditional in your template. Please review your conditionals for an unclosed string, invalid operators, a missing }, or a missing {/if}.

Environment Details:

  • Version: 4.3.6
  • PHP Version: 7.1
  • MySQL Version: 5.7
  • OS: Linux (via Vagrant)
  • Web Server: Apache
@derekjones

This comment has been minimized.

Copy link
Contributor

derekjones commented Nov 30, 2018

I haven't confirmed this report yet, but as a workaround you should be able to use '/\S\S-\S\S/'.

@litzinger

This comment has been minimized.

Copy link
Contributor

litzinger commented Nov 30, 2018

I actually converted to using Resource Router as it was easier to handle 4 url variations the same template, and keep this sort of logic out of the template file.

@kevincupp kevincupp closed this in 7b461c8 Dec 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment