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

Bad formatting inside mixed JS/PHP script block #528

Closed
Niek opened this issue Jun 28, 2019 · 8 comments
Closed

Bad formatting inside mixed JS/PHP script block #528

Niek opened this issue Jun 28, 2019 · 8 comments
Labels
Milestone

Comments

@Niek
Copy link

Niek commented Jun 28, 2019

The following valid PHP code showcases a couple of issues I've seen with the formatter:

<html>
  <body>
    <script>
      var test1 = '<?= $_SERVER['PHP_SELF'] ?>';
      var test2 = "<?= true ? htmlentities('"""') : ''?>";
      var test3 = <?= time() ?>;
    </script>
  </body>
</html>

When formatting this code, it results in the following screwed up code:

<html>

<body>
    <script>
        var test1 = '<?= $_SERVER['
        PHP_SELF '] ?>';
        var test2 = "<?= true ? htmlentities('"
        ""
        ') : '
        ' ?>";
        var test3 = < ? = time() ? > ;
    </script>
</body>

</html>
@bmewburn bmewburn added the bug label Jun 28, 2019
@bmewburn bmewburn changed the title Formatter issues with inline code Bad formatting inside mixed JS/PHP script block Jul 6, 2019
@bmewburn bmewburn modified the milestones: 1.2, 1.1.2 Jul 8, 2019
@bmewburn bmewburn closed this as completed Jul 9, 2019
@Niek
Copy link
Author

Niek commented Jul 9, 2019

Thanks for fixing this!

@Niek
Copy link
Author

Niek commented Jul 9, 2019

Actually it's not completely fixed, here is another test case which goes wrong:

<html><body><script>
var test = {
    <?= $condition ? 'item1' : 'item2' ?>: <?= $data ?>
};
</script></body></html>

Output after formatting:

<html>

<body>
    <script>
        var test = {
            <
            ? php ? > : <?= $condition ? 'item1' : 'item2' ?>
        };
    </script>
</body>

</html>

@bmewburn bmewburn removed this from the 1.1.2 milestone Jul 9, 2019
@bmewburn bmewburn reopened this Jul 9, 2019
@bmewburn bmewburn added this to the 1.1.3 milestone Jul 9, 2019
@Niek
Copy link
Author

Niek commented Jul 11, 2019

Thanks, I didn't spot any more formatting issues!

@saurfang587
Copy link

image

version 1.1.4

@bmewburn
Copy link
Owner

bmewburn commented Jul 12, 2019

@saurfang587 please post code, not screenshots. I cant reproduce this. When I format a similar snippet I get the following.
Edit: looks like the php tag at the top is what prevents it from formatting

Before format:

<script>
<?php $this->foo() ?> //this breaks below formatting
function
_test(myVar)
{
$('.selector').picker({
"a":
true,
"b":
myVar        
});
}

</script>

After format:

<script>
function
_test(myVar) {
    $('.selector').picker({
        "a": true,
        "b": myVar
    });
}
</script>

@bmewburn
Copy link
Owner

@saurfang587 this is upstream - beautifier/js-beautify#1687

Place a comment before the first php tag as a workaround.

@fahim-86
Copy link

fahim-86 commented Jun 2, 2021

Hi @bmewburn my code get changed after save

Before Save
ajax: '{{ route('deal-datatable')}}',

After Save
ajax: '{{ route('
deal - datatable ' )}}',

Can you please help me providing a solution?

@saraswat19
Copy link

Hi @bmewburn my code get changed after save

Before Save
ajax: '{{ route('deal-datatable')}}',

After Save
ajax: '{{ route('
deal - datatable ' )}}',

Can you please help me providing a solution?

Try
ajax: "{{ route('deal-datatable') }}",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants