Skip to content

Commit 30ec645

Browse files
Adjust grapheme_strpos behavior for PHP versions
1 parent 7dd94e4 commit 30ec645

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Patchwork/PHP/Shim/Intl.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ private static function grapheme_position($s, $needle, $offset, $mode)
213213
if ($offset > 0) {
214214
$s = self::grapheme_substr($s, $offset);
215215
} elseif ($offset < 0) {
216-
$offset = 0;
216+
if (defined('HHVM_VERSION_ID') || PHP_VERSION_ID < 50535 || (50600 <= PHP_VERSION_ID && PHP_VERSION_ID < 50621) || (70000 <= PHP_VERSION_ID && PHP_VERSION_ID < 70006)) {
217+
$offset = 0;
218+
} else {
219+
return false;
220+
}
217221
}
218222

219223
switch ($mode) {

tests/PHP/Shim/IntlTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ public function testGrapheme_strpos()
122122
$this->assertSame(false, grapheme_strpos('abc', ''));
123123
$this->assertSame(false, grapheme_strpos('abc', 'd'));
124124
$this->assertSame(false, grapheme_strpos('abc', 'a', 3));
125-
$this->assertSame(0, grapheme_strpos('abc', 'a', 0));
125+
if (defined('HHVM_VERSION_ID') || PHP_VERSION_ID < 50535 || (PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50621) || (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID < 70006)) {
126+
$this->assertSame(0, grapheme_strpos('abc', 'a', -1));
127+
} else {
128+
$this->assertFalse(grapheme_strpos('abc', 'a', -1));
129+
}
126130
$this->assertSame(1, grapheme_strpos('한국어', ''));
127131
$this->assertSame(3, grapheme_stripos('DÉJÀ', 'à'));
128132
$this->assertSame(false, grapheme_strrpos('한국어', ''));
@@ -132,7 +136,11 @@ public function testGrapheme_strpos()
132136
$this->assertSame(false, p::grapheme_strpos('abc', ''));
133137
$this->assertSame(false, p::grapheme_strpos('abc', 'd'));
134138
$this->assertSame(false, p::grapheme_strpos('abc', 'a', 3));
135-
$this->assertSame(0, p::grapheme_strpos('abc', 'a', -1));
139+
if (defined('HHVM_VERSION_ID') || PHP_VERSION_ID < 50535 || (50600 <= PHP_VERSION_ID && PHP_VERSION_ID < 50621) || (70000 <= PHP_VERSION_ID && PHP_VERSION_ID < 70006)) {
140+
$this->assertSame(0, p::grapheme_strpos('abc', 'a', -1));
141+
} else {
142+
$this->assertFalse(p::grapheme_strpos('abc', 'a', -1));
143+
}
136144
$this->assertSame(1, p::grapheme_strpos('한국어', ''));
137145
$this->assertSame(3, p::grapheme_stripos('DÉJÀ', 'à'));
138146
$this->assertSame(false, p::grapheme_strrpos('한국어', ''));

0 commit comments

Comments
 (0)