Skip to content

Commit dc670cb

Browse files
committed
Fix GH-13199: Redundant prompt in phpdbg with libedit/readline
When using libedit/readline integration in phpdbg: ./configure --with-libedit --enable-phpdbg-readline EOF makes editline write prompt again in local console mode. For example, this can be noticed when reading phpt test files from STDIN and running phpdbg: ./sapi/cli/php run-tests.php sapi/phpdbg Closes GH-13199
1 parent b282dd7 commit dc670cb

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

Diff for: NEWS

+4
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

Diff for: sapi/phpdbg/phpdbg_cmd.c

+25-9
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
phpdbg_write("%s", phpdbg_get_prompt());
761777
phpdbg_consume_stdin_line(buf);

0 commit comments

Comments
 (0)