-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Allow empty needles in mbstring functions #4977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--TEST-- | ||
Test mb_stripos() function : with empty needle | ||
--SKIPIF-- | ||
<?php | ||
extension_loaded('mbstring') or die('skip'); | ||
function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build"); | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
mb_internal_encoding('UTF-8'); | ||
|
||
$string_ascii = 'abc def'; | ||
// Japanese string in UTF-8 | ||
$string_mb = "日本語テキストです。0123456789。"; | ||
|
||
echo "\n-- ASCII string without offset --\n"; | ||
var_dump(mb_stripos($string_ascii, '')); | ||
|
||
echo "\n-- ASCII string with in range positive offset --\n"; | ||
var_dump(mb_stripos($string_ascii, '', 2)); | ||
|
||
echo "\n-- ASCII string with in range negative offset --\n"; | ||
var_dump(mb_stripos($string_ascii, '', -2)); | ||
|
||
echo "\n-- ASCII string with out of bound positive offset --\n"; | ||
var_dump(mb_stripos($string_ascii, '', 150)); | ||
|
||
echo "\n-- ASCII string with out of bound negative offset --\n"; | ||
var_dump(mb_stripos($string_ascii, '', -150)); | ||
|
||
|
||
echo "\n-- Multi-byte string without offset --\n"; | ||
var_dump(mb_stripos($string_mb, '')); | ||
|
||
echo "\n-- Multi-byte string with in range positive offset --\n"; | ||
var_dump(mb_stripos($string_mb, '', 2)); | ||
|
||
echo "\n-- Multi-byte string with in range negative offset --\n"; | ||
var_dump(mb_stripos($string_mb, '', -2)); | ||
|
||
echo "\n-- Multi-byte string with out of bound positive offset --\n"; | ||
var_dump(mb_stripos($string_mb, '', 150)); | ||
|
||
echo "\n-- Multi-byte string with out of bound negative offset --\n"; | ||
var_dump(mb_stripos($string_mb, '', -150)); | ||
|
||
?> | ||
--EXPECTF-- | ||
-- ASCII string without offset -- | ||
int(0) | ||
|
||
-- ASCII string with in range positive offset -- | ||
int(2) | ||
|
||
-- ASCII string with in range negative offset -- | ||
int(5) | ||
|
||
-- ASCII string with out of bound positive offset -- | ||
|
||
Warning: mb_stripos(): Offset not contained in string in %s on line %d | ||
bool(false) | ||
|
||
-- ASCII string with out of bound negative offset -- | ||
|
||
Warning: mb_stripos(): Offset not contained in string in %s on line %d | ||
bool(false) | ||
|
||
-- Multi-byte string without offset -- | ||
int(0) | ||
|
||
-- Multi-byte string with in range positive offset -- | ||
int(2) | ||
|
||
-- Multi-byte string with in range negative offset -- | ||
int(19) | ||
|
||
-- Multi-byte string with out of bound positive offset -- | ||
|
||
Warning: mb_stripos(): Offset not contained in string in %s on line %d | ||
bool(false) | ||
|
||
-- Multi-byte string with out of bound negative offset -- | ||
|
||
Warning: mb_stripos(): Offset not contained in string in %s on line %d | ||
bool(false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--TEST-- | ||
Test mb_stristr() function : with empty needle | ||
--SKIPIF-- | ||
<?php | ||
extension_loaded('mbstring') or die('skip'); | ||
function_exists('mb_stristr') or die("skip mb_stristr() is not available in this build"); | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
mb_internal_encoding('UTF-8'); | ||
|
||
$string_ascii = 'abc def'; | ||
// Japanese string in UTF-8 | ||
$string_mb = "日本語テキストです。0123456789。"; | ||
|
||
echo "\n-- ASCII string --\n"; | ||
var_dump(mb_stristr($string_ascii, '', false, 'ISO-8859-1')); | ||
var_dump(mb_stristr($string_ascii, '')); | ||
var_dump(mb_stristr($string_ascii, '', true)); | ||
|
||
echo "\n-- Multibyte string --\n"; | ||
var_dump(mb_stristr($string_mb, '')); | ||
var_dump(mb_stristr($string_mb, '', false, 'utf-8')); | ||
var_dump(mb_stristr($string_mb, '', true)); | ||
|
||
?> | ||
--EXPECT-- | ||
-- ASCII string -- | ||
string(7) "abc def" | ||
string(7) "abc def" | ||
string(0) "" | ||
|
||
-- Multibyte string -- | ||
string(53) "日本語テキストです。0123456789。" | ||
string(53) "日本語テキストです。0123456789。" | ||
string(0) "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--TEST-- | ||
Test mb_strpos() function : with empty needle | ||
--SKIPIF-- | ||
<?php | ||
extension_loaded('mbstring') or die('skip'); | ||
function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build"); | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
mb_internal_encoding('UTF-8'); | ||
|
||
$string_ascii = 'abc def'; | ||
// Japanese string in UTF-8 | ||
$string_mb = "日本語テキストです。0123456789。"; | ||
|
||
echo "\n-- ASCII string without offset --\n"; | ||
var_dump(mb_strpos($string_ascii, '')); | ||
|
||
echo "\n-- ASCII string with in range positive offset --\n"; | ||
var_dump(mb_strpos($string_ascii, '', 2)); | ||
|
||
echo "\n-- ASCII string with in range negative offset --\n"; | ||
var_dump(mb_strpos($string_ascii, '', -2)); | ||
|
||
echo "\n-- ASCII string with out of bound positive offset --\n"; | ||
var_dump(mb_strpos($string_ascii, '', 15)); | ||
|
||
echo "\n-- ASCII string with out of bound negative offset --\n"; | ||
var_dump(mb_strpos($string_ascii, '', -15)); | ||
|
||
|
||
echo "\n-- Multi-byte string without offset --\n"; | ||
var_dump(mb_strpos($string_mb, '')); | ||
|
||
echo "\n-- Multi-byte string with in range positive offset --\n"; | ||
var_dump(mb_strpos($string_mb, '', 2)); | ||
|
||
echo "\n-- Multi-byte string with in range negative offset --\n"; | ||
var_dump(mb_strpos($string_mb, '', -2)); | ||
|
||
echo "\n-- Multi-byte string with out of bound positive offset --\n"; | ||
var_dump(mb_strpos($string_mb, '', 150)); | ||
|
||
echo "\n-- Multi-byte string with out of bound negative offset --\n"; | ||
var_dump(mb_strpos($string_mb, '', -150)); | ||
|
||
?> | ||
--EXPECTF-- | ||
-- ASCII string without offset -- | ||
int(0) | ||
|
||
-- ASCII string with in range positive offset -- | ||
int(2) | ||
|
||
-- ASCII string with in range negative offset -- | ||
int(5) | ||
|
||
-- ASCII string with out of bound positive offset -- | ||
|
||
Warning: mb_strpos(): Offset not contained in string in %s on line %d | ||
bool(false) | ||
|
||
-- ASCII string with out of bound negative offset -- | ||
|
||
Warning: mb_strpos(): Offset not contained in string in %s on line %d | ||
bool(false) | ||
|
||
-- Multi-byte string without offset -- | ||
int(0) | ||
|
||
-- Multi-byte string with in range positive offset -- | ||
int(2) | ||
|
||
-- Multi-byte string with in range negative offset -- | ||
int(19) | ||
|
||
-- Multi-byte string with out of bound positive offset -- | ||
|
||
Warning: mb_strpos(): Offset not contained in string in %s on line %d | ||
bool(false) | ||
|
||
-- Multi-byte string with out of bound negative offset -- | ||
|
||
Warning: mb_strpos(): Offset not contained in string in %s on line %d | ||
bool(false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--TEST-- | ||
Test mb_strrchr() function : with empty needle | ||
--SKIPIF-- | ||
<?php | ||
extension_loaded('mbstring') or die('skip'); | ||
function_exists('mb_strrchr') or die("skip mb_strrchr() is not available in this build"); | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
mb_internal_encoding('UTF-8'); | ||
|
||
$string_ascii = 'abc def'; | ||
// Japanese string in UTF-8 | ||
$string_mb = "日本語テキストです。0123456789。"; | ||
|
||
echo "\n-- ASCII string --\n"; | ||
var_dump(bin2hex(mb_strrchr($string_ascii, '', false, 'ISO-8859-1'))); | ||
var_dump(bin2hex(mb_strrchr($string_ascii, ''))); | ||
var_dump(bin2hex(mb_strrchr($string_ascii, '', true))); | ||
|
||
echo "\n-- Multibyte string --\n"; | ||
var_dump(bin2hex(mb_strrchr($string_mb, ''))); | ||
var_dump(bin2hex(mb_strrchr($string_mb, '', false, 'utf-8'))); | ||
var_dump(bin2hex(mb_strrchr($string_mb, '', true))); | ||
|
||
?> | ||
--EXPECT-- | ||
-- ASCII string -- | ||
string(0) "" | ||
string(0) "" | ||
string(0) "" | ||
|
||
-- Multibyte string -- | ||
string(0) "" | ||
string(0) "" | ||
string(0) "" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I move the
if (offset < 0)
condition out? As it's the same for both now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable.