Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclosed single quote in php tag causes formatting changes which break php code #1377

Closed
esetnik opened this issue Apr 16, 2018 · 0 comments
Closed

Comments

@esetnik
Copy link

esetnik commented Apr 16, 2018

This issue is opened by request in #490 (comment)

Description

$_SERVER['DOCUMENT_ROOT '] will be broken after formatting php code sample below with js-beautify. This was originally discovered as an issue with vscode-php-cs-fixer which relies on js-beautify for html beautification. See junstyle/vscode-php-cs-fixer#42

Input

The code looked like this before beautification:

<a href='' onclick='doIt("<?php echo str_replace("'", "\\ ", $var); ?>  "); '>
  Test
</a>
                
<?php include_once $_SERVER['DOCUMENT_ROOT'] . "/shared/helpModal.php";  ?>

Expected Output

The code should have looked like this after beautification:

<a href='' onclick='doIt("<?php echo str_replace("'", "\\ ", $var); ?>  "); '>
                            Test
                        </a>
                
<?php include_once $_SERVER['DOCUMENT_ROOT'] . "/shared/helpModal.php";  ?>

Actual Output

The code actually looked like this after beautification:

<a href='' onclick='doIt("<?php echo str_replace("' ", "\\ ", $var); ?>  "); '>
                            Test
                        </a>
                
<?php include_once $_SERVER['DOCUMENT_ROOT '] . "/shared/helpModal.php";  ?>

Note the single space added at the end of 'DOCUMENT_ROOT' in associative array reference. This changes the key.

Steps to Reproduce

  1. Go to jsbeautfy.org
  2. Paste above example
  3. See actual output instead of expected output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants