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
Updated by Sebastian Kurfuerst about 19 years ago
Hi,
is it possible for you to attach a unified diff?
Furthermore, it would be great if you could use the preg*-Functions instead of ereg, then the patch could get to the core.
Thanks,
Sebastian
Updated by Sebastian Kurfuerst almost 19 years ago
Hi,
It would be great if you could have a look at it again.
Thanks and greets, Sebastian
Updated by Marc Wöhlken almost 19 years ago
What does UNIFIED diff mean?
My fix was created for V 3.7. You probably want it diff'ed into V 3.8?
Could you please include diff params as i am not very used to this program?!
Updated by Sebastian Kurfuerst almost 19 years ago
maxhb: Just create it with -u (u for unified)
so:
diff -u oldfile newfile > save_to_file.diff
and then upload save_to_file.diff here
The diff against 3.7 is ok I suppose, if nothing changed between the versions. I'll check this then.
Could you please adress the following things:
- use preg instead of ereg functions
- I think you need to use ? (the quantifier minimizer) for the preg so it will work as well when there are multiple <a href...> tags.
Thanks for your efforts, and greets,
Sebastian
Updated by Marc Wöhlken almost 19 years ago
Hi!
Here's the diff asked for.
It's done against Version 3.7
Question: Is using preg-function instead of ereg a new coding guideline for the typo3 core? It seems the preg-functions are usually faster...
CU
maxhb
Updated by Sebastian Kurfuerst almost 19 years ago
Hi,
yes, preg over ereg is a new guideline to be used in the core - exactly because of the speed improvements.
Greets, Sebastian