Issue Bug Closed

#14900Minor problem with tslib_fe::prefixLocalAnchorsWithScript()

Marc Wöhlken 08/03/05, 22:48 updated 08/12/06, 14:22

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
—>
—>
—>
—>

Testing new version of prefixLocalAnchorsWithScript
—>
—>
—>
—>

Test and demonstration script:
<?php

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(
‘‘,
‘
‘,
‘
‘,
‘
‘,
);

echo “Testing current version of prefixLocalAnchorsWithScript
“;
foreach($tags as $tag) {
echo htmlentities($tag) . “ —> “ . htmlentities(prefixLocalAnchorsWithScript($tag)) . “
“;
}

echo “


“;
echo “Testing new version of prefixLocalAnchorsWithScript
“;
foreach($tags as $tag) {
echo htmlentities($tag) . “ —> “ . htmlentities(prefixLocalAnchorsWithScript_new($tag)) . “
“;
}

?>

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)

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.