Skip to content

Commit 4cc1d9e

Browse files
committed
parameter and bbcode simple values now allow non-conflicting syntax tokens inside
1 parent 884dd95 commit 4cc1d9e

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/Parser/RegularParser.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,9 @@ private function value()
238238
return $this->match(self::TOKEN_DELIMITER, false) ? $value : false;
239239
}
240240

241-
if('' !== $tmp = $this->match(self::TOKEN_STRING, false)) {
242-
$value .= $tmp;
243-
while('' !== $tmp = $this->match(self::TOKEN_STRING, false)) {
244-
$value .= $tmp;
241+
if($this->lookahead(self::TOKEN_STRING) || $this->lookahead(self::TOKEN_MARKER)) {
242+
while(false === ($this->lookahead(self::TOKEN_WS) || $this->lookahead(self::TOKEN_CLOSE) || $this->lookaheadN(array(self::TOKEN_MARKER, self::TOKEN_CLOSE)))) {
243+
$value .= $this->match(null, false);
245244
}
246245

247246
return $value;
@@ -302,12 +301,28 @@ private function lookahead($type)
302301
return $this->position < $this->tokensCount && $this->tokens[$this->position][0] === $type;
303302
}
304303

305-
/**
306-
* @param int|null $type
307-
* @param bool $ws
308-
*
309-
* @return string
310-
*/
304+
private function lookaheadN(array $types)
305+
{
306+
$count = count($types);
307+
if($this->position + $count > $this->tokensCount) {
308+
return false;
309+
}
310+
311+
$position = $this->position;
312+
foreach($types as $type) {
313+
// note: automatically skips whitespace tokens
314+
if($this->tokens[$position][0] === self::TOKEN_WS) {
315+
$position++;
316+
}
317+
if($type !== $this->tokens[$position][0]) {
318+
return false;
319+
}
320+
$position++;
321+
}
322+
323+
return true;
324+
}
325+
311326
private function match($type, $ws)
312327
{
313328
if($this->position >= $this->tokensCount) {

tests/ParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ public function provideShortcodes()
232232
array($s, '[a=0 b=0]0[/a]', array(
233233
new ParsedShortcode(new Shortcode('a', array('b' => '0'), '0', '0'), '[a=0 b=0]0[/a]', 0),
234234
)),
235+
array($s, '[x=/[/] [y a=/"//] [z=http://url/] [a=http://url ]', array(
236+
new ParsedShortcode(new Shortcode('x', array(), null, '/['), '[x=/[/]', 0),
237+
new ParsedShortcode(new Shortcode('y', array('a' => '/"/'), null, null), '[y a=/"//]', 8),
238+
new ParsedShortcode(new Shortcode('z', array(), null, 'http://url'), '[z=http://url/]', 19),
239+
new ParsedShortcode(new Shortcode('a', array(), null, 'http://url'), '[a=http://url ]', 35),
240+
)),
235241
);
236242

237243
/**

0 commit comments

Comments
 (0)