Skip to content

Commit

Permalink
Merge pull request tchwork#59 from remicollet/issue-5621
Browse files Browse the repository at this point in the history
fix for php 5.5.35/5.6.21/7.0.6
  • Loading branch information
nicolas-grekas committed May 18, 2016
2 parents 3bd61bc + a06e40a commit e544aae
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Patchwork/Utf8.php
Expand Up @@ -235,7 +235,9 @@ public static function strlen($s)
}
public static function strpos($s, $needle, $offset = 0)
{
return grapheme_strpos($s, $needle, $offset);
// ignore invalid negative offset to keep compatility
// with php < 5.5.35, < 5.6.21, < 7.0.6
return grapheme_strpos($s, $needle, $offset > 0 ? $offset : 0);
}
public static function strrpos($s, $needle, $offset = 0)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/PHP/Shim/IntlTest.php
Expand Up @@ -122,7 +122,7 @@ public function testGrapheme_strpos()
$this->assertSame(false, grapheme_strpos('abc', ''));
$this->assertSame(false, grapheme_strpos('abc', 'd'));
$this->assertSame(false, grapheme_strpos('abc', 'a', 3));
$this->assertSame(0, grapheme_strpos('abc', 'a', -1));
$this->assertSame(0, grapheme_strpos('abc', 'a', 0));
$this->assertSame(1, grapheme_strpos('한국어', '국'));
$this->assertSame(3, grapheme_stripos('DÉJÀ', 'à'));
$this->assertSame(false, grapheme_strrpos('한국어', ''));
Expand Down
3 changes: 2 additions & 1 deletion tests/Utf8/HhvmTest.php
Expand Up @@ -12,7 +12,8 @@ public function test1()
public function test2()
{
// Negative offset are not allowed but native PHP silently casts them to zero
$this->assertSame(0, grapheme_strpos('abc', 'a', -1));
// Starting with 5.5.35, 5.6.21, 7.0.6, PHP refuse them
$this->assertSame(0, grapheme_strpos('abc', 'a', 0));
}

public function test3()
Expand Down

0 comments on commit e544aae

Please sign in to comment.