mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fixing anchor selection
This commit is contained in:
parent
1a6655b2e2
commit
2dd8d5e518
@ -581,8 +581,12 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
||||
}
|
||||
|
||||
// Similar to the regex found in HtmlEditorField.js / getAnchors method.
|
||||
if (preg_match_all("/\s(name|id)=\"([^\"]+?)\"|\s(name|id)='([^']+?)'/im", $page->Content, $matches)) {
|
||||
$anchors = array_filter(array_merge($matches[2], $matches[4]));
|
||||
if (preg_match_all(
|
||||
"/\s+(name|id)\s*=\s*([\"'])([^\\2\s>]*?)\\2|\s+(name|id)\s*=\s*([^\"']+)[\s +>]/im",
|
||||
$page->Content,
|
||||
$matches
|
||||
)) {
|
||||
$anchors = array_filter(array_merge($matches[3], $matches[5]));
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -716,7 +716,8 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
|
||||
// http://www.w3.org/TR/1999/REC-html401-19991224/struct/links.html#h-12.2
|
||||
|
||||
if(ed) {
|
||||
var raw = ed.getContent().match(/\s(name|id)="([^"]+?)"|\s(name|id)='([^']+?)'/gim);
|
||||
var raw = ed.getContent()
|
||||
.match(/\s+(name|id)\s*=\s*(["'])([^\2\s>]*?)\2|\s+(name|id)\s*=\s*([^"']+)[\s +>]/gim);
|
||||
if (raw && raw.length) {
|
||||
for(var i = 0; i < raw.length; i++) {
|
||||
var indexStart = (raw[i].indexOf('id=') == -1) ? 7 : 5;
|
||||
|
@ -116,6 +116,43 @@ class HtmlEditorFieldTest extends FunctionalTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetAnchors() {
|
||||
if (!class_exists('Page')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
$html = '<div name="foo"></div>
|
||||
<div name=\'bar\'></div>
|
||||
<div id="baz"></div>
|
||||
<div id=\'bam\'></div>
|
||||
<div id = "baz"></div>
|
||||
<div id = ""></div>
|
||||
<div id="some\'id"></div>
|
||||
<div id=bar></div>';
|
||||
$expected = array(
|
||||
'foo',
|
||||
'bar',
|
||||
'baz',
|
||||
'bam',
|
||||
"some'id",
|
||||
'bar',
|
||||
);
|
||||
$page = new Page();
|
||||
$page->Title = 'Test';
|
||||
$page->Content = $html;
|
||||
$page->write();
|
||||
$this->useDraftSite(true);
|
||||
|
||||
$controller = new Controller();
|
||||
$controller->setRequest(new SS_HTTPRequest('GET', '/', array(
|
||||
'PageID' => $page->ID,
|
||||
)));
|
||||
$controller->init();
|
||||
|
||||
$toolBar = new HtmlEditorField_Toolbar($controller, 'test');
|
||||
|
||||
$this->assertEquals(json_encode($expected), $toolBar->getanchors());
|
||||
}
|
||||
|
||||
public function testHtmlEditorFieldFileLocal() {
|
||||
$file = new HtmlEditorField_File('http://domain.com/folder/my_image.jpg?foo=bar');
|
||||
$this->assertEquals('http://domain.com/folder/my_image.jpg?foo=bar', $file->URL);
|
||||
|
Loading…
Reference in New Issue
Block a user