Skip to content

Commit a06e40a

Browse files
committed
fix tests for php 5.5.35/5.6.21/7.0.6
1 parent 3bd61bc commit a06e40a

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/Patchwork/Utf8.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ public static function strlen($s)
235235
}
236236
public static function strpos($s, $needle, $offset = 0)
237237
{
238-
return grapheme_strpos($s, $needle, $offset);
238+
// ignore invalid negative offset to keep compatility
239+
// with php < 5.5.35, < 5.6.21, < 7.0.6
240+
return grapheme_strpos($s, $needle, $offset > 0 ? $offset : 0);
239241
}
240242
public static function strrpos($s, $needle, $offset = 0)
241243
{

tests/PHP/Shim/IntlTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ 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', -1));
125+
$this->assertSame(0, grapheme_strpos('abc', 'a', 0));
126126
$this->assertSame(1, grapheme_strpos('한국어', ''));
127127
$this->assertSame(3, grapheme_stripos('DÉJÀ', 'à'));
128128
$this->assertSame(false, grapheme_strrpos('한국어', ''));

tests/Utf8/HhvmTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public function test1()
1212
public function test2()
1313
{
1414
// Negative offset are not allowed but native PHP silently casts them to zero
15-
$this->assertSame(0, grapheme_strpos('abc', 'a', -1));
15+
// Starting with 5.5.35, 5.6.21, 7.0.6, PHP refuse them
16+
$this->assertSame(0, grapheme_strpos('abc', 'a', 0));
1617
}
1718

1819
public function test3()

0 commit comments

Comments
 (0)