js-beautify icon indicating copy to clipboard operation
js-beautify copied to clipboard

Indentation issue inside php tags on html/php

Open tenzap opened this issue 4 years ago • 1 comments

Description

Part of the PHP code changed while this wasn't expected: (it was indented, it lost indentation).

Command: html-beautify -r -t --templating=php --end-with-newline=true -b expand "file"

Input

The code looked like this before beautification:

<?php $this->load->view('js_init/users/js_users');
if ($users->num_rows() === 0):
	if ($_POST)
	{
		echo "<p><i><?php echo lang('tni_user_not_found'); ?></i></p>";
	}
	else
	{
		echo "<p><i><?php echo lang('tni_user_search_empty'); ?></i></p>";
	}
else: ?>
<p>aa</p>
<?php endif; ?>

Expected Output

The code should have looked like this after beautification:

<?php $this->load->view('js_init/users/js_users');
if ($users->num_rows() === 0):
	if ($_POST)
	{
		echo "<p><i><?php echo lang('tni_user_not_found'); ?></i></p>";
	}
	else
	{
		echo "<p><i><?php echo lang('tni_user_search_empty'); ?></i></p>";
	}
else: ?>
<p>aa</p>
<?php endif; ?>

Actual Output

The code actually looked like this after beautification:

<?php $this->load->view('js_init/users/js_users');
if ($users->num_rows() === 0):
	if ($_POST)
	{
		echo "<p><i><?php echo lang('tni_user_not_found'); ?></i></p>";
}
else
{
echo "<p><i><?php echo lang('tni_user_search_empty'); ?></i></p>";
}
else: ?>
<p>aa</p>
<?php endif; ?>

Steps to Reproduce

Environment

OS: linux debian 11

Settings

default + command: html-beautify -r -t --templating=php --end-with-newline=true -b expand "file"

tenzap avatar Dec 07 '21 11:12 tenzap

I just saw that there is such a terrible <?php inside the text of the echo. That is the culprit. If I remove it, then there is no indentation issue.

So the problem is linked to the presence of some <?php ?> nested inside a another <?php ?> in this case it is hidden in a PHP string

tenzap avatar Dec 07 '21 11:12 tenzap