From c21d6b278cfd522df7fea5da049f885165c76a80 Mon Sep 17 00:00:00 2001 From: Reimar Date: Mon, 6 Jan 2025 21:56:27 +0100 Subject: [PATCH 1/3] sapi/cli: Don't set ini-settings mid-expression in interactive shell --- ext/readline/readline_cli.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c index 8fbe93d648953..8bc3b10fc26b0 100644 --- a/ext/readline/readline_cli.c +++ b/ext/readline/readline_cli.c @@ -649,7 +649,16 @@ static int readline_shell_run(void) /* {{{ */ len = strlen(line); - if (line[0] == '#' && line[1] != '[') { + if (pos + len + 2 > size) { + size = pos + len + 2; + code = erealloc(code, size); + } + memcpy(&code[pos], line, len); + pos += len; + code[pos] = '\n'; + code[++pos] = '\0'; + + if (line[0] == '#' && line[1] != '[' && cli_is_valid_code(code, pos, &prompt)) { char *param = strstr(&line[1], "="); if (param) { zend_string *cmd; @@ -661,21 +670,9 @@ static int readline_shell_run(void) /* {{{ */ add_history(line); zend_string_release_ex(prompt, 0); - /* TODO: This might be wrong! */ - prompt = cli_get_prompt("php", '>'); - continue; } } - if (pos + len + 2 > size) { - size = pos + len + 2; - code = erealloc(code, size); - } - memcpy(&code[pos], line, len); - pos += len; - code[pos] = '\n'; - code[++pos] = '\0'; - if (*line) { add_history(line); history_lines_to_write += 1; From 23c3c470e71fe9607e6a71e42a0beffe1745c8ae Mon Sep 17 00:00:00 2001 From: Reimar Date: Mon, 6 Jan 2025 23:21:29 +0100 Subject: [PATCH 2/3] Fix duplicate history when setting ini --- ext/readline/readline_cli.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c index 8bc3b10fc26b0..5a4f3cb328de6 100644 --- a/ext/readline/readline_cli.c +++ b/ext/readline/readline_cli.c @@ -667,9 +667,6 @@ static int readline_shell_run(void) /* {{{ */ zend_alter_ini_entry_chars_ex(cmd, param, strlen(param), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0); zend_string_release_ex(cmd, 0); - add_history(line); - - zend_string_release_ex(prompt, 0); } } From ece3d361717fee3df24aadfb9fd47f8f4a30530c Mon Sep 17 00:00:00 2001 From: Reimar Date: Tue, 7 Jan 2025 22:43:54 +0100 Subject: [PATCH 3/3] Don't evaluate expression when changing ini, optimize check --- ext/readline/readline_cli.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c index 5a4f3cb328de6..8b5e6a88956f9 100644 --- a/ext/readline/readline_cli.c +++ b/ext/readline/readline_cli.c @@ -649,16 +649,7 @@ static int readline_shell_run(void) /* {{{ */ len = strlen(line); - if (pos + len + 2 > size) { - size = pos + len + 2; - code = erealloc(code, size); - } - memcpy(&code[pos], line, len); - pos += len; - code[pos] = '\n'; - code[++pos] = '\0'; - - if (line[0] == '#' && line[1] != '[' && cli_is_valid_code(code, pos, &prompt)) { + if (line[0] == '#' && line[1] != '[' && pos == 0) { char *param = strstr(&line[1], "="); if (param) { zend_string *cmd; @@ -667,9 +658,23 @@ static int readline_shell_run(void) /* {{{ */ zend_alter_ini_entry_chars_ex(cmd, param, strlen(param), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0); zend_string_release_ex(cmd, 0); + add_history(line); + + zend_string_release_ex(prompt, 0); + prompt = cli_get_prompt("php", '>'); + continue; } } + if (pos + len + 2 > size) { + size = pos + len + 2; + code = erealloc(code, size); + } + memcpy(&code[pos], line, len); + pos += len; + code[pos] = '\n'; + code[++pos] = '\0'; + if (*line) { add_history(line); history_lines_to_write += 1;