Skip to content

Commit 0339d8c

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix phpGH-13199: Redundant prompt in phpdbg with libedit/readline
2 parents 48916ce + 97049b4 commit 0339d8c

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

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

751-
if (!cmd) {
752-
PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
753-
zend_bailout();
771+
add_history(cmd);
772+
buffer = estrdup(cmd);
773+
free(cmd);
754774
}
755-
756-
add_history(cmd);
757-
buffer = estrdup(cmd);
758-
free(cmd);
759775
#else
760776
char buf[PHPDBG_MAX_CMD];
761777
phpdbg_write("%s", phpdbg_get_prompt());

0 commit comments

Comments
 (0)