ENHANCEMENT Shortcodes now support commas as delimiter for attributes (thanks aoneil for help with the regex!) (trac #6868)

BUGFIX HtmlEditorField not inserting shortcodes correctly (trac #6868)
This commit is contained in:
Sean Harvey 2012-03-09 14:25:42 +13:00
parent c59c717d78
commit 49267dbbc4
3 changed files with 7 additions and 8 deletions

View File

@ -370,7 +370,7 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
// All other attributes
switch(this.find(':input[name=LinkType]:checked').val()) {
case 'internal':
href = '[sitetree_link id=' + this.find(':input[name=internal]').val() + ']';
href = '[sitetree_link,id=' + this.find(':input[name=internal]').val() + ']';
if(anchor) href += '#' + anchor;
break;
@ -379,7 +379,7 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
break;
case 'file':
href = '[file_link id=' + this.find(':input[name=file]').val() + ']';
href = '[file_link,id=' + this.find(':input[name=file]').val() + ']';
target = '_blank';
break;

View File

@ -170,10 +170,9 @@ class ShortcodeParser {
if($prefix == '[' && $suffix == ']') {
return substr($matches[0], 1, -1);
}
$attributes = array(); // Parse attributes into into this array.
if(preg_match_all('/(\w+) *= *(?:([\'"])(.*?)\\2|([^ "\'>]+))/', $matches[3], $match, PREG_SET_ORDER)) {
if(preg_match_all('/(\w+) *= *(?:([\'"])(.*?)\\2|([^ ,"\'>]+))/', $matches[3], $match, PREG_SET_ORDER)) {
foreach($match as $attribute) {
if(!empty($attribute[4])) {
$attributes[strtolower($attribute[1])] = $attribute[4];

View File

@ -82,14 +82,14 @@ class ShortcodeParserTest extends SapphireTest {
}
public function testUnquotedArguments() {
$this->assertEquals('', $this->parser->parse('[test_shortcode foo=bar baz = buz]'));
$this->assertEquals('', $this->parser->parse('[test_shortcode,foo=bar,baz = buz]'));
$this->assertEquals(array('foo' => 'bar', 'baz' => 'buz'), $this->arguments);
}
public function testSelfClosingTag() {
$this->assertEquals (
'morecontent',
$this->parser->parse('[test_shortcode id="1"/]more[test_shortcode id="2"]content[/test_shortcode]'),
$this->parser->parse('[test_shortcode,id="1"/]more[test_shortcode,id="2"]content[/test_shortcode]'),
'Assert that self-closing tags are respected during parsing.'
);