Skip to content

Commit 147c379

Browse files
committed
simple parameter value enclosed in quotes is now properly matched, added support for escaping parameter values
1 parent e79d668 commit 147c379

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/Syntax.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getArgumentsRegex()
3737
$equals = $this->quote($this->getParameterValueSeparator());
3838
$string = $this->quote($this->getParameterValueDelimiter());
3939

40-
return '~(?:\s+(\w+(?:(?=\s|$)|'.$equals.'\w+|'.$equals.$string.'.+'.$string.')))~us';
40+
return '~(?:\s+(\w+(?:(?=\s|$)|'.$equals.'\w+|'.$equals.$string.'([^'.$string.'\\\\]*(?:\\\\.[^'.$string.'\\\\]*)*?)'.$string.')))~us';
4141
}
4242

4343
private function createShortcodeRegex()

tests/ParserTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public function provideShortcodes()
3333
array('[sc x="multi'."\n".'line"]', 'sc', array('x' => 'multi'."\n".'line'), null),
3434
array('[sc noval x="val" y]content[/sc]', 'sc', array('noval'=> null, 'x' => 'val', 'y' => null), 'content'),
3535
array('[sc x="{..}"]', 'sc', array('x' => '{..}'), null),
36+
array('[sc a="x y" b="x" c=""]', 'sc', array('a' => 'x y', 'b' => 'x', 'c' => ''), null),
37+
array('[sc a="a \"\" b"]', 'sc', array('a' => 'a \"\" b'), null),
3638
);
3739
}
3840

@@ -53,4 +55,14 @@ public function testWithDifferentSyntax()
5355
$this->assertSame('val oth', $shortcode->getParameter('arg'));
5456
$this->assertSame('cont', $shortcode->getContent());
5557
}
58+
59+
public function testDifferentSyntaxEscapedQuotes()
60+
{
61+
$parser = new Parser(new Syntax('^', '$', '&', '!!!', '@@'));
62+
$shortcode = $parser->parse('^code a!!!@@\"\"@@ b!!!@@x\"y@@ c$cnt^&code$');
63+
64+
$this->assertSame('code', $shortcode->getName());
65+
$this->assertSame(array('a' => '\\"\\"', 'b' => 'x\"y', 'c' => null), $shortcode->getParameters());
66+
$this->assertSame('cnt', $shortcode->getContent());
67+
}
5668
}

0 commit comments

Comments
 (0)