psysh: Newline characters are introduced into long lines, causing bugs/errors. Lines >4096 chars are truncated.
I believe I’m seeing 1024-byte buffering at play here and, when an input line exceeds that length, newlines are introduced into the PHP input (at every 1024-character boundary), which can cause bugs and errors.
This might be connected to #155 ?
For example, with exactly 1024 dots, plus the 2 double-quote characters wrapping them:
>>> "................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................"
... => """
..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\n
..
"""
(Scrolling to the end of the line shows the introduced newline, and we see how two of the dots have been pushed to the following line.)
We can easily see how this can cause bugs:
For instance, the following array key is corrupted:
>>> $x["................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................"] = "foo";
... => "foo"
>>> $x
=> [
"...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\n....." => "foo",
]
And here the newline corrupts the code and causes a parse error:
>>> $x = "....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................."; $x;
... PHP Parse error: Syntax error, unexpected T_STRING, expecting T_VARIABLE or '{' or '$' on line 2
Due to the newline being inserted between the $ and the x of the latter instance of $x, which turns that code into this:
>>> $
x
... PHP Parse error: Syntax error, unexpected T_STRING, expecting T_VARIABLE or '{' or '$' on line 2
More generally, using PHP input where the newlines have been removed will mean that boundaries could occur at any arbitrary position in the code, so all manner of different failures may result.
Can we eliminate these additional newlines?
(I found this on account of my own workaround for #490 in which I am automatically eliminating newlines in order to prevent PsySH commands being executed, which is now triggering this new bug for larger inputs 😕 )
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (4 by maintainers)
Agreed, I think we’re done here.
I almost hate it when that amount of time and effort boils down to a one-line code change, but it’s a good thing really 😃
I concur with keeping the
Transientbehaviour distinct from whatHoaConsoleis doing. When I started to look at that I was thinking perhaps there was some code or an approach that Transient could appropriate; but once I realised what HoaConsole was doing I decided that things were good just as they were.