|
16 | 16 | #include "common/wrappers/string_view.h" |
17 | 17 | #include "runtime-common/core/runtime-core.h" |
18 | 18 | #include "runtime-common/core/utils/kphp-assert-core.h" |
| 19 | +#include "runtime-common/stdlib/array/array-functions.h" |
19 | 20 | #include "runtime-common/stdlib/string/string-context.h" |
20 | 21 |
|
21 | 22 | const char* get_mask(const string& what) noexcept { |
@@ -1241,12 +1242,12 @@ string f$stripslashes(const string& str) noexcept { |
1241 | 1242 |
|
1242 | 1243 | Optional<int64_t> f$stripos(const string& haystack, const string& needle, int64_t offset) noexcept { |
1243 | 1244 | if (offset < 0) { |
1244 | | - php_warning("Wrong offset = %" PRIi64 " in function stripos", offset); |
1245 | | - return false; |
| 1245 | + offset += haystack.size(); |
1246 | 1246 | } |
1247 | | - if (offset >= haystack.size()) { |
| 1247 | + if (offset < 0 || offset >= haystack.size()) { |
1248 | 1248 | return false; |
1249 | 1249 | } |
| 1250 | + |
1250 | 1251 | if (needle.size() == 0) { |
1251 | 1252 | php_warning("Parameter needle is empty in function stripos"); |
1252 | 1253 | return false; |
@@ -1726,12 +1727,12 @@ int64_t f$strnatcmp(const string& lhs, const string& rhs) noexcept { |
1726 | 1727 |
|
1727 | 1728 | Optional<int64_t> f$strpos(const string& haystack, const string& needle, int64_t offset) noexcept { |
1728 | 1729 | if (offset < 0) { |
1729 | | - php_warning("Wrong offset = %" PRIi64 " in function strpos", offset); |
1730 | | - return false; |
| 1730 | + offset += haystack.size(); |
1731 | 1731 | } |
1732 | | - if (offset > int64_t{haystack.size()}) { |
| 1732 | + if (offset < 0 || offset >= haystack.size()) { |
1733 | 1733 | return false; |
1734 | 1734 | } |
| 1735 | + |
1735 | 1736 | if (needle.size() <= 1) { |
1736 | 1737 | if (needle.size() == 0) { |
1737 | 1738 | php_warning("Parameter needle is empty in function strpos"); |
|
0 commit comments