Project

General

Profile

Actions

Bug #14900

closed

Minor problem with tslib_fe::prefixLocalAnchorsWithScript()

Added by Marc Wöhlken over 19 years ago. Updated over 18 years ago.

Status:
Closed
Priority:
Should have
Category:
Frontend
Target version:
-
Start date:
2005-08-03
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
3.7.0
PHP Version:
4
Tags:
Complexity:
Is Regression:
Sprint Focus:

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

class.tslib_fe_diff.php (581 Bytes) class.tslib_fe_diff.php Administrator Admin, 2005-12-12 14:05

Related issues 1 (0 open1 closed)

Has duplicate TYPO3 Core - Bug #14950: prefixLocalAnchorsWithScript should allow arbitrary data between the tag's start and the href attributeClosedMichael Stucki2005-08-30

Actions
Actions

Also available in: Atom PDF