While adding some more tests for the BBC parser, I found a little tricky situation:
[img alt=some text height=100 width=150]http://i.imgur.com/eO1zpA7.jpg%20http://i384.photobucket.com/albums/oo283/piter91/spoiler_zpsvzbgpxcv.png[/img]
This one is parsed into:
<img src="http://i.imgur.com/eO1zpA7.jpg%20http://i384.photobucket.com/albums/oo283/piter91/spoiler_zpsvzbgpxcv.png" alt="some text height=100" style="width:100%;max-width:150px;" class="bbc_img resized" />
The wrong part is the alt attribute:
alt="some text height=100"
It's indeed an edge case because 1) the alt parameter doesn't have any validation, as such, anything it has inside is good, 2) for a chance, the first regex that is tested and matches is:
~^(\s+alt=(.+?))?(\s+width=(\d+))?(\s+height=(\d+))?\]~i
Sooo, options:
1) whistle innocently and ignore it (possible),
2) make the alt a quoted parameter,
3) find a fix.
At the moment I just found what I think it's a workaround changing the exit condition to:
} while ((!$match || count($matches) !== (count($keys) * 2 + 1)) && --$max_iterations && ($keys = pc_next_permutation($keys, $possible['regex_size'])));
in particular, the original:
!$match
changed to:
(!$match || count($matches) !== (count($keys) * 2 + 1))
That relies on the fact that if not all matches are found, something may be wrong and keeps trying.
Though, I have the feeling this will break in cases there are less than the maximum number of parameter. But I should test it more in details, also I'm not sure of the impact in case of bbcodes with "too many" parameter.
Opinions?