From cf86c6b1e6caaccb5ad2f9af3b4f936eeefc2b64 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 27 Apr 2025 18:25:25 +0100 Subject: [PATCH 1/5] ext/curl: CURLOPT_FOLLOWLOCATION option handling. it had been considered as boolean for years but since 8.13, it can accept values beyond 1L, respectively CURLFOLLOW_OBEYCODE and CURLFOLLOW_FIRSTONLY. --- ext/curl/curl.stub.php | 13 +++++++++++++ ext/curl/curl_arginfo.h | 8 +++++++- ext/curl/interface.c | 6 +----- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ext/curl/curl.stub.php b/ext/curl/curl.stub.php index 6a73913f8a85e..d8bd141751047 100644 --- a/ext/curl/curl.stub.php +++ b/ext/curl/curl.stub.php @@ -497,6 +497,19 @@ */ const CURLOPT_DEBUGFUNCTION = UNKNOWN; +#if LIBCURL_VERSION_NUM >= 0x080d00 /* Available since 8.13.0 */ +/** + * @var int + * @cvalue CURLFOLLOW_OBEYCODE + */ +const CURLFOLLOW_OBEYCODE = UNKNOWN; +/** + * @var int + * @cvalue CURLFOLLOW_FIRSTONLY + */ +const CURLFOLLOW_FIRSTONLY = UNKNOWN; +#endif + /** * @var int * @cvalue CURLINFO_TEXT diff --git a/ext/curl/curl_arginfo.h b/ext/curl/curl_arginfo.h index 53a59fe47be49..96254fd062828 100644 --- a/ext/curl/curl_arginfo.h +++ b/ext/curl/curl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 77da3a34f08b3e932a0545f72b41bf0353e8b157 */ + * Stub hash: 3d718a50e8ee0a3a776bf5930d850a6c44f7a738 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_close, 0, 1, IS_VOID, 0) ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0) @@ -326,6 +326,12 @@ static void register_curl_symbols(int module_number) REGISTER_LONG_CONSTANT("CURLOPT_WRITEHEADER", CURLOPT_WRITEHEADER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CURLOPT_XFERINFOFUNCTION", CURLOPT_XFERINFOFUNCTION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CURLOPT_DEBUGFUNCTION", CURLOPT_DEBUGFUNCTION, CONST_PERSISTENT); +#if LIBCURL_VERSION_NUM >= 0x080d00 /* Available since 8.13.0 */ + REGISTER_LONG_CONSTANT("CURLFOLLOW_OBEYCODE", CURLFOLLOW_OBEYCODE, CONST_PERSISTENT); +#endif +#if LIBCURL_VERSION_NUM >= 0x080d00 /* Available since 8.13.0 */ + REGISTER_LONG_CONSTANT("CURLFOLLOW_FIRSTONLY", CURLFOLLOW_FIRSTONLY, CONST_PERSISTENT); +#endif REGISTER_LONG_CONSTANT("CURLINFO_TEXT", CURLINFO_TEXT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CURLINFO_HEADER_IN", CURLINFO_HEADER_IN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CURLINFO_DATA_IN", CURLINFO_DATA_IN, CONST_PERSISTENT); diff --git a/ext/curl/interface.c b/ext/curl/interface.c index a087da78c37e4..7328401f516fd 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -1863,6 +1863,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue #if LIBCURL_VERSION_NUM >= 0x080900 /* Available since 8.9.0 */ case CURLOPT_TCP_KEEPCNT: #endif + case CURLOPT_FOLLOWLOCATION: lval = zval_get_long(zvalue); if ((option == CURLOPT_PROTOCOLS || option == CURLOPT_REDIR_PROTOCOLS) && (PG(open_basedir) && *PG(open_basedir)) && (lval & CURLPROTO_FILE)) { @@ -2210,11 +2211,6 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue /* Do nothing, just backward compatibility */ break; - case CURLOPT_FOLLOWLOCATION: - lval = zend_is_true(zvalue); - error = curl_easy_setopt(ch->cp, option, lval); - break; - case CURLOPT_POSTFIELDS: if (Z_TYPE_P(zvalue) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_P(zvalue)) == 0) { From 218e65dee92a6a332306c6c7d70d656d6ab0571f Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 27 Apr 2025 19:39:28 +0100 Subject: [PATCH 2/5] test attempt --- .../curl_setopt_CURLOPT_FOLLOWLOCATION.phpt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt diff --git a/ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt b/ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt new file mode 100644 index 0000000000000..d80b2b77ab0f0 --- /dev/null +++ b/ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt @@ -0,0 +1,32 @@ +--TEST-- +CURLOPT_FOLLOWLOCATION values +--EXTENSIONS-- +curl +--SKIPIF-- += 8.13.0'); +if (ini_get('open_basedir')) exit("skip open_basedir is set"); +?> +--FILE-- + +--EXPECTF-- +bool(true) +string(%d) "%s" +bool(true) +string(%d) "%s" +bool(true) +string(%d) "%s" +bool(true) +string(%d) "%s" + From 0d676b58cba2f155127ec545e779b05b95142bd6 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 27 Apr 2025 19:57:12 +0100 Subject: [PATCH 3/5] UPGRADING entries --- UPGRADING | 13 +++++++++++++ .../tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/UPGRADING b/UPGRADING index 6fd01ab0e370f..7150f29e006c6 100644 --- a/UPGRADING +++ b/UPGRADING @@ -153,6 +153,12 @@ PHP 8.5 UPGRADE NOTES CURLOPT_INFILESIZE only accepts a 32-bit signed integer as the file size (2.0 GiB) even on 64-bit systems. CURLOPT_INFILESIZE_LARGE accepts the largest integer value the system can handle. + . Added CURLFOLLOW_OBEYCODE and CURLFOLLOW_FIRSTONLY value for + CURLOPT_FOLLOWLOCATION curl_easy_setopt option. + CURLFOLLOW_OBEYCODE to follow more strictly in regard of redirect + if they are allowed. CURLFOLLOW_FIRSTONLY to follow only the + first redirect thus if there any follow up redirect, it won't go + any further. - DOM: . Added Dom\Element::$outerHTML. @@ -351,6 +357,11 @@ PHP 8.5 UPGRADE NOTES 9. Other Changes to Extensions ======================================== +- Curl: + . curl_easy_setopt with CURLOPT_FOLLOWLOCATION option's value no longer + is treated as boolean but integer to handle CURLFOLLOW_OBEYCODE and + CURLFOLLOW_FIRSTONLY. + - Fileinfo: . Upgraded to file 5.46. . The return type of finfo_close() has been changed to true, rather @@ -377,6 +388,8 @@ PHP 8.5 UPGRADE NOTES . CURLINFO_HTTPAUTH_USED. . CURLINFO_PROXYAUTH_USED. . CURLOPT_INFILESIZE_LARGE. + . CURLFOLLOW_OBEYCODE. + . CURLFOLLOW_FIRSTONLY. - Intl: . DECIMAL_COMPACT_SHORT. diff --git a/ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt b/ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt index d80b2b77ab0f0..6bfc399f38a4d 100644 --- a/ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt +++ b/ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt @@ -6,7 +6,6 @@ curl = 8.13.0'); -if (ini_get('open_basedir')) exit("skip open_basedir is set"); ?> --FILE-- Date: Mon, 28 Apr 2025 21:48:13 +0100 Subject: [PATCH 4/5] while at it, adding CURLFOLLOW_ALL. --- UPGRADING | 6 ++++-- ext/curl/curl.stub.php | 5 +++++ ext/curl/curl_arginfo.h | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/UPGRADING b/UPGRADING index 7150f29e006c6..1968989cee1de 100644 --- a/UPGRADING +++ b/UPGRADING @@ -153,12 +153,13 @@ PHP 8.5 UPGRADE NOTES CURLOPT_INFILESIZE only accepts a 32-bit signed integer as the file size (2.0 GiB) even on 64-bit systems. CURLOPT_INFILESIZE_LARGE accepts the largest integer value the system can handle. - . Added CURLFOLLOW_OBEYCODE and CURLFOLLOW_FIRSTONLY value for + . Added CURLFOLLOW_OBEYCODE, CURLFOLLOW_FIRSTONLY and CURLFOLLOW_ALL values for CURLOPT_FOLLOWLOCATION curl_easy_setopt option. CURLFOLLOW_OBEYCODE to follow more strictly in regard of redirect if they are allowed. CURLFOLLOW_FIRSTONLY to follow only the first redirect thus if there any follow up redirect, it won't go - any further. + any further. CURLFOLLOW_ALL is equivalent to set CURLOPT_FOLLOWLOCATION + to true. - DOM: . Added Dom\Element::$outerHTML. @@ -388,6 +389,7 @@ PHP 8.5 UPGRADE NOTES . CURLINFO_HTTPAUTH_USED. . CURLINFO_PROXYAUTH_USED. . CURLOPT_INFILESIZE_LARGE. + . CURLFOLLOW_ALL. . CURLFOLLOW_OBEYCODE. . CURLFOLLOW_FIRSTONLY. diff --git a/ext/curl/curl.stub.php b/ext/curl/curl.stub.php index d8bd141751047..cbcb52bc7b0a2 100644 --- a/ext/curl/curl.stub.php +++ b/ext/curl/curl.stub.php @@ -498,6 +498,11 @@ const CURLOPT_DEBUGFUNCTION = UNKNOWN; #if LIBCURL_VERSION_NUM >= 0x080d00 /* Available since 8.13.0 */ +/** + * @var int + * @cvalue CURLFOLLOW_ALL + */ +const CURLFOLLOW_ALL = UNKNOWN; /** * @var int * @cvalue CURLFOLLOW_OBEYCODE diff --git a/ext/curl/curl_arginfo.h b/ext/curl/curl_arginfo.h index 96254fd062828..8928da3f47453 100644 --- a/ext/curl/curl_arginfo.h +++ b/ext/curl/curl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 3d718a50e8ee0a3a776bf5930d850a6c44f7a738 */ + * Stub hash: 792cdfa8a8ce190d73dffe679c51a41a2ee46cd7 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_close, 0, 1, IS_VOID, 0) ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0) @@ -326,6 +326,9 @@ static void register_curl_symbols(int module_number) REGISTER_LONG_CONSTANT("CURLOPT_WRITEHEADER", CURLOPT_WRITEHEADER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CURLOPT_XFERINFOFUNCTION", CURLOPT_XFERINFOFUNCTION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CURLOPT_DEBUGFUNCTION", CURLOPT_DEBUGFUNCTION, CONST_PERSISTENT); +#if LIBCURL_VERSION_NUM >= 0x080d00 /* Available since 8.13.0 */ + REGISTER_LONG_CONSTANT("CURLFOLLOW_ALL", CURLFOLLOW_ALL, CONST_PERSISTENT); +#endif #if LIBCURL_VERSION_NUM >= 0x080d00 /* Available since 8.13.0 */ REGISTER_LONG_CONSTANT("CURLFOLLOW_OBEYCODE", CURLFOLLOW_OBEYCODE, CONST_PERSISTENT); #endif From 217d604a5c3277cd4e76d1d5dedbcaf7135accc9 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 29 Apr 2025 20:48:12 +0100 Subject: [PATCH 5/5] fix test --- ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt b/ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt index 6bfc399f38a4d..31661e2eaffb9 100644 --- a/ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt +++ b/ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION.phpt @@ -10,11 +10,16 @@ if (curl_version()['version_number'] < 0x080d00) die('skip requires curl >= 8.13 --FILE--