xref: /PHP-7.4/ext/mbstring/tests/bug45923.phpt (revision 487d4d07)
1--TEST--
2Bug #45923 (mb_st[r]ripos() offset not handled correctly)
3--SKIPIF--
4<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5--FILE--
6<?php
7
8function section($func, $haystack, $needle)
9{
10	echo "\n------- $func -----------\n\n";
11	foreach(array(0, 3, 6, 9, 11, 12, -1, -3, -6, -20) as $offset) {
12		echo "> Offset: $offset\n";
13		var_dump($func($haystack,$needle,$offset));
14	}
15}
16
17section('strpos'     , "abc abc abc"  , "abc");
18section('mb_strpos'  , "●○◆ ●○◆ ●○◆", "●○◆");
19
20section('stripos'    , "abc abc abc"  , "abc");
21section('mb_stripos' , "●○◆ ●○◆ ●○◆", "●○◆");
22
23section('strrpos'    , "abc abc abc"  , "abc");
24section('mb_strrpos' , "●○◆ ●○◆ ●○◆", "●○◆");
25
26section('strripos'   , "abc abc abc"  , "abc");
27section('mb_strripos', "●○◆ ●○◆ ●○◆", "●○◆");
28?>
29--EXPECTF--
30------- strpos -----------
31
32> Offset: 0
33int(0)
34> Offset: 3
35int(4)
36> Offset: 6
37int(8)
38> Offset: 9
39bool(false)
40> Offset: 11
41bool(false)
42> Offset: 12
43
44Warning: strpos(): Offset not contained in string in %s on line %d
45bool(false)
46> Offset: -1
47bool(false)
48> Offset: -3
49int(8)
50> Offset: -6
51int(8)
52> Offset: -20
53
54Warning: strpos(): Offset not contained in string in %s on line %d
55bool(false)
56
57------- mb_strpos -----------
58
59> Offset: 0
60int(0)
61> Offset: 3
62int(4)
63> Offset: 6
64int(8)
65> Offset: 9
66bool(false)
67> Offset: 11
68bool(false)
69> Offset: 12
70
71Warning: mb_strpos(): Offset not contained in string in %s on line %d
72bool(false)
73> Offset: -1
74bool(false)
75> Offset: -3
76int(8)
77> Offset: -6
78int(8)
79> Offset: -20
80
81Warning: mb_strpos(): Offset not contained in string in %s on line %d
82bool(false)
83
84------- stripos -----------
85
86> Offset: 0
87int(0)
88> Offset: 3
89int(4)
90> Offset: 6
91int(8)
92> Offset: 9
93bool(false)
94> Offset: 11
95bool(false)
96> Offset: 12
97
98Warning: stripos(): Offset not contained in string in %s on line %d
99bool(false)
100> Offset: -1
101bool(false)
102> Offset: -3
103int(8)
104> Offset: -6
105int(8)
106> Offset: -20
107
108Warning: stripos(): Offset not contained in string in %s on line %d
109bool(false)
110
111------- mb_stripos -----------
112
113> Offset: 0
114int(0)
115> Offset: 3
116int(4)
117> Offset: 6
118int(8)
119> Offset: 9
120bool(false)
121> Offset: 11
122bool(false)
123> Offset: 12
124
125Warning: mb_stripos(): Offset not contained in string in %s on line %d
126bool(false)
127> Offset: -1
128bool(false)
129> Offset: -3
130int(8)
131> Offset: -6
132int(8)
133> Offset: -20
134
135Warning: mb_stripos(): Offset not contained in string in %s on line %d
136bool(false)
137
138------- strrpos -----------
139
140> Offset: 0
141int(8)
142> Offset: 3
143int(8)
144> Offset: 6
145int(8)
146> Offset: 9
147bool(false)
148> Offset: 11
149bool(false)
150> Offset: 12
151
152Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
153bool(false)
154> Offset: -1
155int(8)
156> Offset: -3
157int(8)
158> Offset: -6
159int(4)
160> Offset: -20
161
162Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
163bool(false)
164
165------- mb_strrpos -----------
166
167> Offset: 0
168int(8)
169> Offset: 3
170int(8)
171> Offset: 6
172int(8)
173> Offset: 9
174bool(false)
175> Offset: 11
176bool(false)
177> Offset: 12
178
179Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
180bool(false)
181> Offset: -1
182int(8)
183> Offset: -3
184int(8)
185> Offset: -6
186int(4)
187> Offset: -20
188
189Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
190bool(false)
191
192------- strripos -----------
193
194> Offset: 0
195int(8)
196> Offset: 3
197int(8)
198> Offset: 6
199int(8)
200> Offset: 9
201bool(false)
202> Offset: 11
203bool(false)
204> Offset: 12
205
206Warning: strripos(): Offset is greater than the length of haystack string in %s on line %d
207bool(false)
208> Offset: -1
209int(8)
210> Offset: -3
211int(8)
212> Offset: -6
213int(4)
214> Offset: -20
215
216Warning: strripos(): Offset is greater than the length of haystack string in %s on line %d
217bool(false)
218
219------- mb_strripos -----------
220
221> Offset: 0
222int(8)
223> Offset: 3
224int(8)
225> Offset: 6
226int(8)
227> Offset: 9
228bool(false)
229> Offset: 11
230bool(false)
231> Offset: 12
232
233Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
234bool(false)
235> Offset: -1
236int(8)
237> Offset: -3
238int(8)
239> Offset: -6
240int(4)
241> Offset: -20
242
243Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
244bool(false)
245