BUG Fix shortcode parsing in HTMLEditorField::getanchors()

Fixes #5678
This commit is contained in:
Damian Mooyman 2016-06-17 16:28:58 +12:00
parent 009f2de17c
commit 6a7c1056fe
3 changed files with 18 additions and 6 deletions

View File

@ -76,6 +76,7 @@ class DB {
if(isset(self::$connections[$name])) {
return self::$connections[$name];
}
return null;
}
/**

View File

@ -606,10 +606,13 @@ class HTMLEditorField_Toolbar extends RequestHandler {
);
}
// Parse the shortcodes so [img id=x] doesn't end up as anchor x
$htmlValue = $page->obj('Content')->forTemplate();
// Similar to the regex found in HTMLEditorField.js / getAnchors method.
if (preg_match_all(
"/\\s+(name|id)\\s*=\\s*([\"'])([^\\2\\s>]*?)\\2|\\s+(name|id)\\s*=\\s*([^\"']+)[\\s +>]/im",
$page->Content,
$htmlValue,
$matches
)) {
$anchors = array_values(array_unique(array_filter(

View File

@ -126,14 +126,22 @@ class HTMLEditorFieldTest extends FunctionalTest {
if (!class_exists('Page')) {
$this->markTestSkipped();
}
$html = '<div name="foo"></div>
<div name=\'bar\'></div>
$linkedPage = new Page();
$linkedPage->Title = 'Dummy';
$linkedPage->write();
$html = <<<EOS
<div name="foo"></div>
<div name='bar'></div>
<div id="baz"></div>
<div id=\'bam\'></div>
[sitetree_link id="{$linkedPage->ID}"]
<div id='bam'></div>
<div id = "baz"></div>
<div id = ""></div>
<div id="some\'id"></div>
<div id=bar></div>';
<div id="some'id"></div>
<div id=bar></div>
EOS
;
$expected = array(
'foo',
'bar',