NEW DATE! Bugzilla will undergo maintenance 2024-03-28 18h00 CET. Bugzilla will be placed in read-only mode at that time.

Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 528379 - formatter breaks PHP code inside <style> tags
Summary: formatter breaks PHP code inside <style> tags
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: PHP Core CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 493808
  Show dependency tree
 
Reported: 2017-12-10 06:52 EST by Hans Henrik Bergan CLA
Modified: 2020-05-14 11:24 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hans Henrik Bergan CLA 2017-12-10 06:52:06 EST
this code: 


<style>
<?php
$str='';
foreach($errLines as $errLine){
	$str.='pre ol li:nth-child('.$errLine.'), ';
}
$str=rtrim($str,', ');
?>

</style>


formats into: 

<style>
<?
php
 $str = '';
foreach ( $errLines as $errLine ) {
	$str .= 'pre ol li:nth-child(' . $errLine . '),
	';
}
$
str
=rtrim ( $str, ',
' );
?>
</style>


- which is both ugly, and outright breaks the code, making it uncompilable (using the built-in "PHP Convention" formatter profile).

Eclipse version: 
Version: Photon Milestone 2 (4.8.0M2)
Build id: 20170922-0530

Eclipse PDT version: 5.2.0.2017091910
Comment 1 Hans Henrik Bergan CLA 2017-12-10 06:57:00 EST
and even if you fix the obvious syntax errors, it subtly alters the behavior of the remaining code,  thus the "importance level: Major"
Comment 2 Thierry BLIND CLA 2017-12-15 05:55:37 EST
Hi Hans,
it seems that in <style> tags you have 2 formatters that conflicts:
- the php formatter tries to format <?php ?> section first
- afterwards there's some eclipse formatter that formats <style> tag content

I have no solution yet, better never include other things than valid css content inside <style> tags, you should better do something like that:

<?php
echo "<style>\n";
$str='';
foreach($errLines as $errLine){
	$str.='pre ol li:nth-child('.$errLine.'), ';
}
$str=rtrim($str,', ');
echo "</style>\n";
?>

If I remember well, there was already a very old bug talking about this problem.

Thierry.
Comment 3 Hans Henrik Bergan CLA 2017-12-15 08:50:36 EST
>  If I remember well, there was already a very old bug talking about this problem.

i went looking for one before submitting this bugreport, but couldn't find it. and yeah, i ended up doing a workaround like that,

	// written this way because of eclipse formatter bugs,
	// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=528379
	echo '<style>' . $str . ' {background-color:red;}</style>';
	?>
<style>
~~
Comment 4 Thierry BLIND CLA 2017-12-15 10:23:37 EST
I found it again ;) It was (more or less) bug 493808.
Comment 5 Eclipse Genie CLA 2020-01-09 09:12:58 EST
New Gerrit change created: https://git.eclipse.org/r/155547
Comment 7 Thierry BLIND CLA 2020-01-09 09:52:59 EST
Fixed.

We simply don't use the CSS code formatter anymore inside <style> tags that contain some PHP code. This way the PHP code formatter will work as expected, but the rest of the CSS code will remain untouched. That's a little drawback, but probably the best we can (or should) do in this very specific case.

Thierry.