Bug #14900
closedMinor problem with tslib_fe::prefixLocalAnchorsWithScript()
0%
Description
prefixLocalAnchorsWithScript does only work correctly if the href attribute is the first attribute of an a or area tag. This is a problem e.g. when using qcom_htmlcleaner which will eventually change the order of html attributes (which should not matter at all).
Demonstration script and output:
Testing current version of prefixLocalAnchorsWithScript
<a href="#"> --> <a href="index.php#">
<a href="# title="My Anchor"> --> <a href="index.php# title="My Anchor">
<a title="My Anchor" href="#"> --> <a title="My Anchor" href="#">
<a id="foo_bar" title="My Anchor" href="#" name="bar"> --> <a id="foo_bar" title="My Anchor" href="#" name="bar">
Testing new version of prefixLocalAnchorsWithScript
<a href="#"> --> <a href="index.php#">
<a href="# title="My Anchor"> --> <a href="index.php# title="My Anchor">
<a title="My Anchor" href="#"> --> <a title="My Anchor" href="index.php#">
<a id="foo_bar" title="My Anchor" href="#" name="bar"> --> <a id="foo_bar" title="My Anchor" href="index.php#" name="bar">
Test and demonstration script:
function prefixLocalAnchorsWithScript($tag,$scriptPath = 'index.php') {
return eregi_replace('(<(a|area)[[:space:]]+href=")(#[^"]*")','\1'.htmlspecialchars($scriptPath).'\3',$tag);
}
function prefixLocalAnchorsWithScript_new($tag,$scriptPath = 'index.php') {
return eregi_replace('(<(a|area).+href=")(#[^"]*")','\1'.htmlspecialchars($scriptPath).'\3',$tag);
}
$tags = array(
'<a href="#">',
'<a href="# title="My Anchor">',
'<a title="My Anchor" href="#">',
'<a id="foo_bar" title="My Anchor" href="#" name="bar">',
);
echo "Testing current version of prefixLocalAnchorsWithScript<br>";
foreach($tags as $tag) {
echo htmlentities($tag) . " --> " . htmlentities(prefixLocalAnchorsWithScript($tag)) . "<br>";
}
echo "<hr>";
echo "Testing new version of prefixLocalAnchorsWithScript<br>";
foreach($tags as $tag) {
echo htmlentities($tag) . " --> " . htmlentities(prefixLocalAnchorsWithScript_new($tag)) . "<br>";
}
?>
FIX: Change prefixLocalAnchorsWithScript to:
function prefixLocalAnchorsWithScript() {
$scriptPath = substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'),strlen(t3lib_div::getIndpEnv('TYPO3_SITE_URL')));
$this->content = eregi_replace('(<(a|area).+href=")(#[^"]*")','\1'.htmlspecialchars($scriptPath).'\3',$this->content);
}
(issue imported from #M1343)
Files