Skip to content

Commit f1660ae

Browse files
committed
parameter and bbcode simple values now allow non-conflicting syntax tokens inside
1 parent ccf16e8 commit f1660ae

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/Parser/RegularParser.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,9 @@ private function value()
200200
return $this->match(self::TOKEN_DELIMITER, false) ? $value : false;
201201
}
202202

203-
if($tmp = $this->match(self::TOKEN_STRING, false)) {
204-
$value .= $tmp;
205-
while($tmp = $this->match(self::TOKEN_STRING, false)) {
206-
$value .= $tmp;
203+
if($this->lookahead(self::TOKEN_STRING) || $this->lookahead(self::TOKEN_MARKER)) {
204+
while(false === ($this->lookahead(self::TOKEN_WS) || $this->lookahead(self::TOKEN_CLOSE) || $this->lookaheadN(array(self::TOKEN_MARKER, self::TOKEN_CLOSE)))) {
205+
$value .= $this->match(null, false);
207206
}
208207

209208
return $value;
@@ -252,6 +251,28 @@ private function lookahead($type)
252251
return $this->position < $this->tokensCount && $this->tokens[$this->position][0] === $type;
253252
}
254253

254+
private function lookaheadN(array $types)
255+
{
256+
$count = count($types);
257+
if($this->position + $count > $this->tokensCount) {
258+
return false;
259+
}
260+
261+
$position = $this->position;
262+
foreach($types as $type) {
263+
// note: automatically skips whitespace tokens
264+
if($this->tokens[$position][0] === self::TOKEN_WS) {
265+
$position++;
266+
}
267+
if($type !== $this->tokens[$position][0]) {
268+
return false;
269+
}
270+
$position++;
271+
}
272+
273+
return true;
274+
}
275+
255276
private function match($type, $ws)
256277
{
257278
if($this->position >= $this->tokensCount) {

tests/ParserTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ public function provideShortcodes()
225225
new ParsedShortcode(new Shortcode('y', array(), ' ] [] [ [z] [/#] [/z] [ [] ] [/] ', null), '[y] ] [] [ [z] [/#] [/z] [ [] ] [/] [/y]', 27),
226226
new ParsedShortcode(new Shortcode('z', array(), ' [ [/ [/] /] ] ', null), '[z] [ [/ [/] /] ] [/z]', 70),
227227
)),
228+
array($s, '[x=/[/] [y a=/"//] [z=http://url/] [a=http://url ]', array(
229+
new ParsedShortcode(new Shortcode('x', array(), null, '/['), '[x=/[/]', 0),
230+
new ParsedShortcode(new Shortcode('y', array('a' => '/"/'), null, null), '[y a=/"//]', 8),
231+
new ParsedShortcode(new Shortcode('z', array(), null, 'http://url'), '[z=http://url/]', 19),
232+
new ParsedShortcode(new Shortcode('a', array(), null, 'http://url'), '[a=http://url ]', 35),
233+
)),
228234
);
229235

230236
/**
@@ -239,7 +245,7 @@ public function provideShortcodes()
239245
*
240246
* Tests cases from array above with identifiers in the array below must be skipped.
241247
*/
242-
$wordpressSkip = array(3, 6, 16, 21, 22, 23, 25, 32, 33, 34, 46, 47, 49);
248+
$wordpressSkip = array(3, 6, 16, 21, 22, 23, 25, 32, 33, 34, 46, 47, 49, 51);
243249
$result = array();
244250
foreach($tests as $key => $test) {
245251
$syntax = array_shift($test);

0 commit comments

Comments
 (0)