Skip to content

Commit 590cbfb

Browse files
committed
parameter and bbcode simple values now allow non-conflicting syntax tokens inside
1 parent dd33d8c commit 590cbfb

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/Parser/RegularParser.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ private function value()
210210
return $this->match(self::TOKEN_DELIMITER) ? $value : false;
211211
}
212212

213-
if($this->match(self::TOKEN_STRING, $appendValue)) {
214-
while($this->match(self::TOKEN_STRING, $appendValue)) {
215-
continue;
213+
if($this->lookahead(self::TOKEN_STRING) || $this->lookahead(self::TOKEN_MARKER)) {
214+
while(false === ($this->lookahead(self::TOKEN_WS) || $this->lookahead(self::TOKEN_CLOSE) || $this->lookaheadN(array(self::TOKEN_MARKER, self::TOKEN_CLOSE)))) {
215+
$this->match(null, $appendValue);
216216
}
217217

218218
return $value;
@@ -258,6 +258,28 @@ private function lookahead($type)
258258
return $this->position < $this->tokensCount && (empty($type) || $this->tokens[$this->position][0] === $type);
259259
}
260260

261+
private function lookaheadN(array $types)
262+
{
263+
$count = count($types);
264+
if($this->position + $count > $this->tokensCount) {
265+
return false;
266+
}
267+
268+
$position = $this->position;
269+
foreach($types as $type) {
270+
// note: automatically skips whitespace tokens
271+
if($this->tokens[$position][0] === self::TOKEN_WS) {
272+
$position++;
273+
}
274+
if($type !== $this->tokens[$position][0]) {
275+
return false;
276+
}
277+
$position++;
278+
}
279+
280+
return true;
281+
}
282+
261283
private function match($type, $callback = null, $ws = false)
262284
{
263285
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)