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

[5.3] Fix #16593 and fix bug introduced in #16607 #16610

Closed
wants to merge 4 commits into from
Closed

[5.3] Fix #16593 and fix bug introduced in #16607 #16610

wants to merge 4 commits into from

Conversation

manan-jadhav
Copy link
Contributor

The regex now handles array syntax, with/without 'or' nicely.

I've added tests to verify that this fixes #16593 .

@GrahamCampbell GrahamCampbell changed the title Fix #16593 and fix bug introduced in #16607 [5.3] Fix #16593 and fix bug introduced in #16607 Nov 30, 2016
@taylorotwell
Copy link
Member

Can you explain this regex in plain English?

@vlakoff
Copy link
Contributor

vlakoff commented Dec 1, 2016

Are you sure the two greedy .+ you have added aren't problematic?

@manan-jadhav
Copy link
Contributor Author

@vlakoff There are unit tests which cover all possibilities, and they pass, so I dont think they're going to cause any problems now. If there are more cases in your head, let me know.

@manan-jadhav
Copy link
Contributor Author

manan-jadhav commented Dec 1, 2016

This is the regex : ^(\$.+(?:\[[\'"].+[\'"]\])|[^\[\]\'"]*)(?:\s+or\s+)(.+)$

Breaking it into three parts :

  1. (\$.+(?:\[[\'"].+[\'"]\])|[^\[\]\'"]*) : This gets captured in group 1 $1.
    Match things that start with a $ then followed by one or more characters (.+) then followed by either of the following

    • (?:\[[\'"].+[\'"]\]) : String that opens with [' or [", then contains characters (using greedy here makes sure the regex doesnt return too early), and then '] or "]. This matches the array access statements.
    • [^\[\]\'"]* : String that is empty, OR, does not contain any of [, ", '. This matches anything except the array access statements.
  2. (?:\s+or\s+) : Matches or, that is, or with whitespace characters around it.

  3. (.+) : This gets captured in group 2 $2. Matches any characters after or.

@taylorotwell
Copy link
Member

Going to hold off on this for now on 5.3 as it's fairly edge case and I don't want to break things again on a minor release.

@vlakoff
Copy link
Contributor

vlakoff commented Dec 2, 2016

Another case to think of, and test, would be dynamic variable names:

$foo = new \StdClass;
$foo->bar = 'content';
$dynName = 'bar';

// note the brackets
{{ $foo->{$dynName} }}

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

Successfully merging this pull request may close these issues.

3 participants