Skip to content

Commit 9e0e8d5

Browse files
committed
Handle mb_str(r)ipos offset consistently as well
1 parent ce61698 commit 9e0e8d5

File tree

5 files changed

+18
-36
lines changed

5 files changed

+18
-36
lines changed

ext/mbstring/mbstring.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,7 @@ PHP_FUNCTION(mb_stripos)
21712171
if (!mbfl_is_error(n)) {
21722172
RETVAL_LONG(n);
21732173
} else {
2174+
handle_strpos_error(n);
21742175
RETVAL_FALSE;
21752176
}
21762177
}
@@ -2194,6 +2195,7 @@ PHP_FUNCTION(mb_strripos)
21942195
if (!mbfl_is_error(n)) {
21952196
RETVAL_LONG(n);
21962197
} else {
2198+
handle_strpos_error(n);
21972199
RETVAL_FALSE;
21982200
}
21992201
}
@@ -4811,26 +4813,6 @@ MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t ol
48114813
break;
48124814
}
48134815

4814-
if (offset != 0) {
4815-
size_t haystack_char_len = mbfl_strlen(&haystack);
4816-
4817-
if (mode) {
4818-
if ((offset > 0 && (size_t)offset > haystack_char_len) ||
4819-
(offset < 0 && (size_t)(-offset) > haystack_char_len)) {
4820-
php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string");
4821-
break;
4822-
}
4823-
} else {
4824-
if (offset < 0) {
4825-
offset += (zend_long)haystack_char_len;
4826-
}
4827-
if (offset < 0 || (size_t)offset > haystack_char_len) {
4828-
php_error_docref(NULL, E_WARNING, "Offset not contained in string");
4829-
break;
4830-
}
4831-
}
4832-
}
4833-
48344816
n = mbfl_strpos(&haystack, &needle, offset, mode);
48354817
} while(0);
48364818

ext/mbstring/tests/bug45923.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ bool(false)
218218
bool(false)
219219
> Offset: 12
220220

221-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
221+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
222222
bool(false)
223223
> Offset: -1
224224
int(8)
@@ -228,5 +228,5 @@ int(8)
228228
int(4)
229229
> Offset: -20
230230

231-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
231+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
232232
bool(false)

ext/mbstring/tests/mb_strpos_offset_errors.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ bool(false)
3232
Warning: mb_stripos(): Offset not contained in string in %s on line %d
3333
bool(false)
3434

35-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
35+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
3636
bool(false)
3737

38-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
38+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
3939
bool(false)

ext/mbstring/tests/mb_strripos_empty_needle.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ int(5)
5858

5959
-- ASCII string with out of bound positive offset --
6060

61-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
61+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
6262
bool(false)
6363

6464
-- ASCII string with out of bound negative offset --
6565

66-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
66+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
6767
bool(false)
6868

6969
-- Multi-byte string without offset --
@@ -77,10 +77,10 @@ int(19)
7777

7878
-- Multi-byte string with out of bound positive offset --
7979

80-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
80+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
8181
bool(false)
8282

8383
-- Multi-byte string with out of bound negative offset --
8484

85-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
85+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
8686
bool(false)

ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,40 +74,40 @@ int(20)
7474
**-- Offset is: 30 --**
7575
-- ASCII String --
7676

77-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
77+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
7878
bool(false)
7979
--Multibyte String --
8080

81-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
81+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
8282
bool(false)
8383

8484
**-- Offset is: 40 --**
8585
-- ASCII String --
8686

87-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
87+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
8888
bool(false)
8989
--Multibyte String --
9090

91-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
91+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
9292
bool(false)
9393

9494
**-- Offset is: 50 --**
9595
-- ASCII String --
9696

97-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
97+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
9898
bool(false)
9999
--Multibyte String --
100100

101-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
101+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
102102
bool(false)
103103

104104
**-- Offset is: 60 --**
105105
-- ASCII String --
106106

107-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
107+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
108108
bool(false)
109109
--Multibyte String --
110110

111-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
111+
Warning: mb_strripos(): Offset not contained in string in %s on line %d
112112
bool(false)
113113
Done

0 commit comments

Comments
 (0)