Merge pull request #4733 from feejin/htmleditorfield-anchor-improvements

Check for id attributes for anchor targets and prevent partial matches
This commit is contained in:
Daniel Hensby 2015-11-11 14:52:32 +00:00
commit 234e5a8a59
2 changed files with 4 additions and 3 deletions

View File

@ -519,7 +519,7 @@ class HtmlEditorField_Toolbar extends RequestHandler {
}
// Similar to the regex found in HtmlEditorField.js / getAnchors method.
if (preg_match_all("/name=\"([^\"]+?)\"|name='([^']+?)'/im", $page->Content, $matches)) {
if (preg_match_all("/\s(name|id)=\"([^\"]+?)\"|\s(name|id)='([^']+?)'/im", $page->Content, $matches)) {
$anchors = $matches[1];
}

View File

@ -716,10 +716,11 @@ 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(/name="([^"]+?)"|name='([^']+?)'/gim);
var raw = ed.getContent().match(/\s(name|id)="([^"]+?)"|\s(name|id)='([^']+?)'/gim);
if (raw && raw.length) {
for(var i = 0; i < raw.length; i++) {
collectedAnchors.push(raw[i].substr(6).replace(/"$/, ''));
var indexStart = (raw[i].indexOf('id=') == -1) ? 7 : 5;
collectedAnchors.push(raw[i].substr(indexStart).replace(/"$/, ''));
}
}
}