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 #1

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

Actions #2

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

Actions #3

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?!

Actions #4

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

Actions #5

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

Actions #6

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

Actions #7

Updated by Sebastian Kurfuerst almost 19 years ago

fixed in CVS.

Actions

Also available in: Atom PDF