Bug #66312 [Opn->Nab]: PHP code inside <script> deletes LF
| From: | rasmus@php.net | Date: | Tue, 17 Dec 2013 23:26:11 +0000 |
| Subject: | Bug #66312 [Opn->Nab]: PHP code inside <script> deletes LF | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-183381@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66312&edit=1
ID: 66312
Updated by: rasmus@php.net
Reported by: danielslcosta at gmail dot com
Summary: PHP code inside <script> deletes LF
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Windows 7
PHP Version: 5.5.7
Block user comment: N
Private report: N
New Comment:
This is on purpose to avoid stray newlines following closing PHP tags that might force out response
headers prematurely which in turn means a subsequent header() call won't work. Not ideal, we
know, but changing this would break a lot of legacy code. You need to put 2 CRs there if you want to
force one or use ?><space><cr>
Previous Comments:
------------------------------------------------------------------------
[2013-12-17 23:19:55] danielslcosta at gmail dot com
Description:
------------
To prevent some editors showing errors in Javascript code with PHP code inside it, I comment the
lines with PHP code.
When you run the code, the alert and </script> goes one line up, and become commented. It
seems it's "eating" the Line Feeds.
Tested with LF and CRLF, both in Windows 7/PHP 5.5.7 TS and CentOS 6.4 with PHP 5.5.5.
If you put a space or any other character after the closing tag ?> it works.
Test script:
---------------
<script type='text/javascript'>
//<?php if (1) { ?>
alert('test');
//<?php } ?>
</script>
<script type='text/javascript'>
//<?php if (1) { ?>/
alert('test');
//<?php } ?>/
</script>
Expected result:
----------------
The JS alert box should pop and the resulting HTML should be:
<script type='text/javascript'>
//
alert('test');
//
</script>
<script type='text/javascript'>
///
alert('test');
///
</script>
Actual result:
--------------
The 'alert' and '</script>' are commented
<script type='text/javascript'>
// alert('test');
//</script>
<script type='text/javascript'>
///
alert('test');
///
</script>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66312&edit=1