From 61b33627c6f3c0fe6524ccbee88e69914d196c44 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Tue, 28 Oct 2025 15:29:22 +0300 Subject: [PATCH 1/3] fix tests.. --- tests/phpt/dl/491_strpos.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/phpt/dl/491_strpos.php b/tests/phpt/dl/491_strpos.php index 1f0ae2ff20..7fc701ef4e 100644 --- a/tests/phpt/dl/491_strpos.php +++ b/tests/phpt/dl/491_strpos.php @@ -52,6 +52,27 @@ var_dump (mb_strtoupper($str, 'UTF-8')); // var_dump(strtolower ("ÈÔÛÛÀÏÂÀ¨")); + var_dump(strpos("abcdABCDefghEFGHefgh", "efgh", -10)); + var_dump(strpos("abcdABCDefghEFGHefgh", "efgh", -16)); + var_dump(strpos("abcdABCDefghEFGh_H", "h", -10)); + var_dump(strpos("abcdABCDefghEFGh_H", "h", -5)); + var_dump(strpos("abcdABCDefghEFGh_H", "h", -2)); + var_dump(strpos("0123456789a123456789b123456789c", "7", -5)); + var_dump(strpos("0123456789a123456789b123456789c", "7", -25)); + var_dump(strpos("0123456789a123456789b123456789c", "c", -1)); + var_dump(strpos("0123456789a123456789b123456789c", "9", -1)); + + var_dump(stripos("abcdABCDefghEFGHefgh", "efgh", -10)); + var_dump(stripos("abcdABCDefghEFGHefgh", "efgh", -16)); + var_dump(stripos("abcdABCDefghEFGh_H", "h", -10)); + var_dump(stripos("abcdABCDefghEFGh_H", "h", -5)); + var_dump(stripos("abcdABCDefghEFGh_H", "h", -2)); + var_dump(stripos("0123456789a123456789b123456789c", "7", -5)); + var_dump(stripos("0123456789a123456789b123456789c", "7", -25)); + var_dump(stripos("0123456789a123456789b123456789c", "c", -1)); + var_dump(stripos("0123456789a123456789b123456789c", "9", -1)); + + $a = array (" ", "The quick brown fox jumped over the lazy dog.", "A very long woooooooooooord.", "A very long wooooooooooooord.", "A very long woooooooooooord.", "", "A very long wooooooooooooord.", "A very long wooooooooooooord 234234234 e r we we r we rwe f w ew r wer we wer wer we r wer ."); foreach ($a as $str) { var_dump (nl2br (wordwrap ($str, 1, "\n", true))); From 60fe4c18365498ee33a035d6d510f61e0f1dec59 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Tue, 28 Oct 2025 15:41:12 +0300 Subject: [PATCH 2/3] fix tests... --- runtime-common/stdlib/string/string-functions.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/runtime-common/stdlib/string/string-functions.cpp b/runtime-common/stdlib/string/string-functions.cpp index 57fb4ebd77..d01c3435aa 100644 --- a/runtime-common/stdlib/string/string-functions.cpp +++ b/runtime-common/stdlib/string/string-functions.cpp @@ -16,6 +16,7 @@ #include "common/wrappers/string_view.h" #include "runtime-common/core/runtime-core.h" #include "runtime-common/core/utils/kphp-assert-core.h" +#include "runtime-common/stdlib/array/array-functions.h" #include "runtime-common/stdlib/string/string-context.h" const char* get_mask(const string& what) noexcept { @@ -1241,12 +1242,12 @@ string f$stripslashes(const string& str) noexcept { Optional f$stripos(const string& haystack, const string& needle, int64_t offset) noexcept { if (offset < 0) { - php_warning("Wrong offset = %" PRIi64 " in function stripos", offset); - return false; + offset += haystack.size(); } - if (offset >= haystack.size()) { + if (offset < 0 || offset >= haystack.size()) { return false; } + if (needle.size() == 0) { php_warning("Parameter needle is empty in function stripos"); return false; @@ -1726,12 +1727,12 @@ int64_t f$strnatcmp(const string& lhs, const string& rhs) noexcept { Optional f$strpos(const string& haystack, const string& needle, int64_t offset) noexcept { if (offset < 0) { - php_warning("Wrong offset = %" PRIi64 " in function strpos", offset); - return false; + offset += haystack.size(); } - if (offset > int64_t{haystack.size()}) { + if (offset < 0 || offset >= haystack.size()) { return false; } + if (needle.size() <= 1) { if (needle.size() == 0) { php_warning("Parameter needle is empty in function strpos"); From 6114e521d2da9644ad2272976ce5acca32662c26 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Tue, 28 Oct 2025 15:46:38 +0300 Subject: [PATCH 3/3] del unused include --- runtime-common/stdlib/string/string-functions.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime-common/stdlib/string/string-functions.cpp b/runtime-common/stdlib/string/string-functions.cpp index d01c3435aa..413b4c2fc5 100644 --- a/runtime-common/stdlib/string/string-functions.cpp +++ b/runtime-common/stdlib/string/string-functions.cpp @@ -16,7 +16,6 @@ #include "common/wrappers/string_view.h" #include "runtime-common/core/runtime-core.h" #include "runtime-common/core/utils/kphp-assert-core.h" -#include "runtime-common/stdlib/array/array-functions.h" #include "runtime-common/stdlib/string/string-context.h" const char* get_mask(const string& what) noexcept {