mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge pull request #1360 from kinglozzer/1359-link-tracking-regex
FIX: preg_quote() anchors in SiteTreeLinkTracking (fixes #1359)
This commit is contained in:
commit
b1387641bf
@ -217,14 +217,18 @@ class SiteTreeLinkTracking_Parser {
|
||||
$matches = array();
|
||||
if(preg_match('/\[sitetree_link(?:\s*|%20|,)?id=([0-9]+)\](#(.*))?/i', $href, $matches)) {
|
||||
$page = DataObject::get_by_id('SiteTree', $matches[1]);
|
||||
$broken = false;
|
||||
|
||||
if (!$page) {
|
||||
// Page doesn't exist.
|
||||
$broken = true;
|
||||
} else if (!empty($matches[3]) && !preg_match("/(name|id)=\"{$matches[3]}\"/", $page->Content)) {
|
||||
} else if (!empty($matches[3])) {
|
||||
$anchor = preg_quote($matches[3], '/');
|
||||
|
||||
if (!preg_match("/(name|id)=\"{$anchor}\"/", $page->Content)) {
|
||||
// Broken anchor on the target page.
|
||||
$broken = true;
|
||||
} else {
|
||||
$broken = false;
|
||||
}
|
||||
}
|
||||
|
||||
$results[] = array(
|
||||
|
@ -32,6 +32,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest {
|
||||
$this->assertFalse($this->isBroken("<a href=\"[sitetree_link,id=$page->ID]#yes-name-anchor\">link</a>"));
|
||||
$this->assertFalse($this->isBroken("<a href=\"[sitetree_link,id=$page->ID]#yes-id-anchor\">link</a>"));
|
||||
$this->assertFalse($this->isBroken("<a href=\"[file_link,id=$file->ID]\">link</a>"));
|
||||
$this->assertTrue($this->isBroken("<a href=\"[sitetree_link,id=$page->ID]#http://invalid-anchor.com\"></a>"));
|
||||
}
|
||||
|
||||
function highlight($content) {
|
||||
|
Loading…
Reference in New Issue
Block a user