Merge pull request #219 from halkyon/master

Fixed HtmlEditorField not inserting file/page links correctly due to broken shortcodes
This commit is contained in:
Sam Minnée 2012-03-08 18:46:03 -08:00
commit f01982a829
3 changed files with 19 additions and 15 deletions

View File

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

View File

@ -170,10 +170,9 @@ class ShortcodeParser {
if($prefix == '[' && $suffix == ']') { if($prefix == '[' && $suffix == ']') {
return substr($matches[0], 1, -1); return substr($matches[0], 1, -1);
} }
$attributes = array(); // Parse attributes into into this array. $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) { foreach($match as $attribute) {
if(!empty($attribute[4])) { if(!empty($attribute[4])) {
$attributes[strtolower($attribute[1])] = $attribute[4]; $attributes[strtolower($attribute[1])] = $attribute[4];

View File

@ -20,12 +20,12 @@ class ShortcodeParserTest extends SapphireTest {
public function testNotRegisteredShortcode() { public function testNotRegisteredShortcode() {
$this->assertEquals('[not_shortcode]', $this->parser->parse('[not_shortcode]')); $this->assertEquals('[not_shortcode]', $this->parser->parse('[not_shortcode]'));
$this->assertEquals('[not_shortcode /]', $this->parser->parse('[not_shortcode /]')); $this->assertEquals('[not_shortcode /]', $this->parser->parse('[not_shortcode /]'));
$this->assertEquals('[not_shortcode foo="bar"]', $this->parser->parse('[not_shortcode foo="bar"]')); $this->assertEquals('[not_shortcode,foo="bar"]', $this->parser->parse('[not_shortcode,foo="bar"]'));
$this->assertEquals('[not_shortcode]a[/not_shortcode]', $this->parser->parse('[not_shortcode]a[/not_shortcode]')); $this->assertEquals('[not_shortcode]a[/not_shortcode]', $this->parser->parse('[not_shortcode]a[/not_shortcode]'));
} }
public function testSimpleTag() { public function testSimpleTag() {
$tests = array('[test_shortcode]', '[test_shortcode ]', '[test_shortcode/]', '[test_shortcode /]'); $tests = array('[test_shortcode]', '[test_shortcode ]', '[test_shortcode,]', '[test_shortcode/]', '[test_shortcode /]');
foreach($tests as $test) { foreach($tests as $test) {
$this->parser->parse($test); $this->parser->parse($test);
@ -38,9 +38,9 @@ class ShortcodeParserTest extends SapphireTest {
public function testOneArgument() { public function testOneArgument() {
$tests = array ( $tests = array (
'[test_shortcode foo="bar"]', '[test_shortcode,foo="bar"]',
"[test_shortcode foo='bar']", "[test_shortcode,foo='bar']",
'[test_shortcode foo = "bar" /]' '[test_shortcode,foo = "bar" /]'
); );
foreach($tests as $test) { foreach($tests as $test) {
@ -53,7 +53,7 @@ class ShortcodeParserTest extends SapphireTest {
} }
public function testMultipleArguments() { public function testMultipleArguments() {
$this->parser->parse('[test_shortcode foo = "bar" bar=\'foo\' baz="buz"]'); $this->parser->parse('[test_shortcode,foo = "bar",bar=\'foo\',baz="buz"]');
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', 'baz' => 'buz'), $this->arguments); $this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', 'baz' => 'buz'), $this->arguments);
$this->assertEquals('', $this->contents); $this->assertEquals('', $this->contents);
@ -69,7 +69,7 @@ class ShortcodeParserTest extends SapphireTest {
} }
public function testEnclosingWithArguments() { public function testEnclosingWithArguments() {
$this->parser->parse('[test_shortcode foo = "bar" bar=\'foo\' baz="buz"]foo[/test_shortcode]'); $this->parser->parse('[test_shortcode,foo = "bar",bar=\'foo\',baz="buz"]foo[/test_shortcode]');
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', 'baz' => 'buz'), $this->arguments); $this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', 'baz' => 'buz'), $this->arguments);
$this->assertEquals('foo', $this->contents); $this->assertEquals('foo', $this->contents);
@ -82,6 +82,11 @@ class ShortcodeParserTest extends SapphireTest {
} }
public function testUnquotedArguments() { public function testUnquotedArguments() {
$this->assertEquals('', $this->parser->parse('[test_shortcode,foo=bar,baz = buz]'));
$this->assertEquals(array('foo' => 'bar', 'baz' => 'buz'), $this->arguments);
}
public function testSpacesForDelimiter() {
$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); $this->assertEquals(array('foo' => 'bar', 'baz' => 'buz'), $this->arguments);
} }
@ -89,7 +94,7 @@ class ShortcodeParserTest extends SapphireTest {
public function testSelfClosingTag() { public function testSelfClosingTag() {
$this->assertEquals ( $this->assertEquals (
'morecontent', '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.' 'Assert that self-closing tags are respected during parsing.'
); );