Merge pull request #3464 from InfinityIo/rewrite_hash_links-SSTemplateParser-fix

Fix over-eager rewrite_hash_links regexp in SSTemplateParser
This commit is contained in:
Sean Harvey 2014-09-26 18:14:08 +12:00
commit c57c24eb81
3 changed files with 17 additions and 5 deletions

View File

@ -1097,6 +1097,7 @@ after')
<body>
<a class="inline" href="#anchor">InlineLink</a>
$InsertedLink
<svg><use xlink:href="#sprite"></use></svg>
<body>
</html>');
$tmpl = new SSViewer($tmplFile);
@ -1111,7 +1112,12 @@ after')
'<a class="inline" href="' . $base . '#anchor">InlineLink</a>',
$result
);
$this->assertContains(
'<svg><use xlink:href="#sprite"></use></svg>',
$result,
'SSTemplateParser should only rewrite anchor hrefs'
);
unlink($tmplFile);
Config::inst()->update('SSViewer', 'rewrite_hash_links', $orig);
@ -1130,6 +1136,7 @@ after')
<body>
<a class="inline" href="#anchor">InlineLink</a>
$InsertedLink
<svg><use xlink:href="#sprite"></use></svg>
<body>
</html>');
$tmpl = new SSViewer($tmplFile);
@ -1145,6 +1152,11 @@ after')
// '<a class="inline" href="<?php echo str_replace(',
// $result
// );
$this->assertContains(
'<svg><use xlink:href="#sprite"></use></svg>',
$result,
'SSTemplateParser should only rewrite anchor hrefs'
);
unlink($tmplFile);

View File

@ -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\') ?' .
'/(<a[^>]+href *= *)"#/i',
'\\1"\' . (Config::inst()->get(\'SSViewer\', \'rewrite_hash_links\') ?' .
' strip_tags( $_SERVER[\'REQUEST_URI\'] ) : "") .
\'#',
$text

View File

@ -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\') ?' .
'/(<a[^>]+href *= *)"#/i',
'\\1"\' . (Config::inst()->get(\'SSViewer\', \'rewrite_hash_links\') ?' .
' strip_tags( $_SERVER[\'REQUEST_URI\'] ) : "") .
\'#',
$text