Skip to content

Commit 97049b4

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-13199: Redundant prompt in phpdbg with libedit/readline
2 parents 4049594 + dc670cb commit 97049b4

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ PHP NEWS
3535
- PDO_Firebird:
3636
. Fix bogus fallthrough path in firebird_handle_get_attribute(). (nielsdos)
3737

38+
- PHPDBG:
39+
. Fixed bug GH-13199 (EOF emits redundant prompt in phpdbg local console mode
40+
with libedit/readline). (Peter Kokot)
41+
3842
- Soap:
3943
. Fixed bug #55639 (Digest autentication dont work). (nielsdos)
4044

sapi/phpdbg/phpdbg_cmd.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include "phpdbg_prompt.h"
2424
#include "phpdbg_io.h"
2525

26+
#ifdef HAVE_UNISTD_H
27+
# include <unistd.h>
28+
#endif
29+
2630
ZEND_EXTERN_MODULE_GLOBALS(phpdbg)
2731

2832
static inline const char *phpdbg_command_name(const phpdbg_command_t *command, char *buffer) {
@@ -746,17 +750,29 @@ PHPDBG_API char *phpdbg_read_input(const char *buffered) /* {{{ */
746750
if ((PHPDBG_G(flags) & (PHPDBG_IS_STOPPING | PHPDBG_IS_RUNNING)) != PHPDBG_IS_STOPPING) {
747751
if (buffered == NULL) {
748752
#ifdef HAVE_PHPDBG_READLINE
749-
char *cmd = readline(phpdbg_get_prompt());
750-
PHPDBG_G(last_was_newline) = 1;
753+
# ifdef HAVE_UNISTD_H
754+
/* EOF makes readline write prompt again in local console mode and
755+
ignored if compiled without readline integration. */
756+
if (!isatty(PHPDBG_G(io)[PHPDBG_STDIN].fd)) {
757+
char buf[PHPDBG_MAX_CMD];
758+
phpdbg_write("%s", phpdbg_get_prompt());
759+
phpdbg_consume_stdin_line(buf);
760+
buffer = estrdup(buf);
761+
} else
762+
# endif
763+
{
764+
char *cmd = readline(phpdbg_get_prompt());
765+
PHPDBG_G(last_was_newline) = 1;
766+
767+
if (!cmd) {
768+
PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
769+
zend_bailout();
770+
}
751771

752-
if (!cmd) {
753-
PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
754-
zend_bailout();
772+
add_history(cmd);
773+
buffer = estrdup(cmd);
774+
free(cmd);
755775
}
756-
757-
add_history(cmd);
758-
buffer = estrdup(cmd);
759-
free(cmd);
760776
#else
761777
phpdbg_write("%s", phpdbg_get_prompt());
762778
phpdbg_consume_stdin_line(buf);

0 commit comments

Comments
 (0)