From 6141930f1588de1a1cb411a5aae1ce28c4ff0c51 Mon Sep 17 00:00:00 2001 From: Nik Date: Tue, 2 Sep 2014 15:16:20 +1200 Subject: [PATCH 1/2] Copy SSViewer rewrite_hash_links regexp to SSTemplateParser As this is meant to represent the same functionality in two different areas, it should behave the same way in both. --- view/SSTemplateParser.php | 4 ++-- view/SSTemplateParser.php.inc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/view/SSTemplateParser.php b/view/SSTemplateParser.php index 1abe84845..3c11980dc 100644 --- a/view/SSTemplateParser.php +++ b/view/SSTemplateParser.php @@ -4682,8 +4682,8 @@ class SSTemplateParser extends Parser implements TemplateParser { // TODO: This is pretty ugly & gets applied on all files not just html. I wonder if we can make this // non-dynamically calculated $text = preg_replace( - '/href\s*\=\s*\"\#/', - 'href="\' . (Config::inst()->get(\'SSViewer\', \'rewrite_hash_links\') ?' . + '/(]+href *= *)"#/i', + '\\1"\' . (Config::inst()->get(\'SSViewer\', \'rewrite_hash_links\') ?' . ' strip_tags( $_SERVER[\'REQUEST_URI\'] ) : "") . \'#', $text diff --git a/view/SSTemplateParser.php.inc b/view/SSTemplateParser.php.inc index 255482aae..74fc27bbe 100644 --- a/view/SSTemplateParser.php.inc +++ b/view/SSTemplateParser.php.inc @@ -1136,8 +1136,8 @@ class SSTemplateParser extends Parser implements TemplateParser { // TODO: This is pretty ugly & gets applied on all files not just html. I wonder if we can make this // non-dynamically calculated $text = preg_replace( - '/href\s*\=\s*\"\#/', - 'href="\' . (Config::inst()->get(\'SSViewer\', \'rewrite_hash_links\') ?' . + '/(]+href *= *)"#/i', + '\\1"\' . (Config::inst()->get(\'SSViewer\', \'rewrite_hash_links\') ?' . ' strip_tags( $_SERVER[\'REQUEST_URI\'] ) : "") . \'#', $text From 5258b84e5c2131b96aed590cc0d89af3a9e54bf4 Mon Sep 17 00:00:00 2001 From: Nik Date: Fri, 26 Sep 2014 17:41:27 +1200 Subject: [PATCH 2/2] Updated SSViewerTest to test for SSTemplateParser rewrite_hash_links fix --- tests/view/SSViewerTest.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/view/SSViewerTest.php b/tests/view/SSViewerTest.php index 474ea1cf6..ff14a838c 100644 --- a/tests/view/SSViewerTest.php +++ b/tests/view/SSViewerTest.php @@ -1097,6 +1097,7 @@ after') InlineLink $InsertedLink + '); $tmpl = new SSViewer($tmplFile); @@ -1111,7 +1112,12 @@ after') 'InlineLink', $result ); - + $this->assertContains( + '', + $result, + 'SSTemplateParser should only rewrite anchor hrefs' + ); + unlink($tmplFile); Config::inst()->update('SSViewer', 'rewrite_hash_links', $orig); @@ -1130,6 +1136,7 @@ after') InlineLink $InsertedLink + '); $tmpl = new SSViewer($tmplFile); @@ -1145,6 +1152,11 @@ after') // '', + $result, + 'SSTemplateParser should only rewrite anchor hrefs' + ); unlink($tmplFile);