File tree 1 file changed +13
-6
lines changed
1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -168,13 +168,14 @@ private function gatherLines(): string {
168
168
}
169
169
170
170
$ input = $ this ->driver ->readline ($ prompt );
171
+ [$ incomplete , $ trim ] = self ::isIncompleteInput ($ input );
171
172
172
- if (self :: isIncompleteInput ( $ input ) ) {
173
+ if ($ incomplete ) {
173
174
174
175
// Consider non-empty line ending with a "\" character as
175
176
// a part of multiline input. That is: Trim the backslash and
176
177
// go read another line from the user.
177
- $ lines .= mb_substr ($ input , 0 , mb_strlen ($ input ) - 1 ) . "\n" ;
178
+ $ lines .= mb_substr ($ input , 0 , mb_strlen ($ input ) - $ trim ) . "\n" ;
178
179
$ gathering = true ;
179
180
180
181
} else {
@@ -194,17 +195,23 @@ private function gatherLines(): string {
194
195
private function isIncompleteInput (string $ input ) {
195
196
196
197
if (empty (trim ($ input ))) {
197
- return false ;
198
+ return [ false , 0 ] ;
198
199
}
199
200
200
201
// Lines ending with opening curly brackets are considered incomplete.
201
- if ($ input [-1 ] === "{ " || $ input [-1 ] === '\\' ) {
202
- return true ;
202
+ if ($ input [-1 ] === "{ " ) {
203
+ return [true , 0 ];
204
+ }
205
+
206
+ // Lines ending with backslashes are considered incomplete.
207
+ // And such backslashes at the EOL are to be trimmed from real input.
208
+ if ($ input [-1 ] === '\\' ) {
209
+ return [true , 1 ];
203
210
}
204
211
205
212
// Lines starting with a SPACE or a TAB are considered incomplete.
206
213
if (strspn ($ input , "\t " ) !== 0 ) {
207
- return true ;
214
+ return [ true , 0 ] ;
208
215
}
209
216
210
217
}
You can’t perform that action at this time.
0 commit comments