mirror of
https://github.com/php/php-src.git
synced 2024-11-25 10:54:15 +08:00
fix bug 55562 - make substr always return rest of the string if length is too long
This commit is contained in:
parent
a948142d31
commit
40217d0417
@ -554,13 +554,17 @@ PHP_FUNCTION(grapheme_substr)
|
||||
length += iter_val;
|
||||
}
|
||||
|
||||
if ( UBRK_DONE == sub_str_end_pos && length < 0) {
|
||||
if ( UBRK_DONE == sub_str_end_pos) {
|
||||
if(length < 0) {
|
||||
|
||||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: length not contained in string", 1 TSRMLS_CC );
|
||||
|
||||
efree(ustr);
|
||||
ubrk_close(bi);
|
||||
RETURN_FALSE;
|
||||
} else {
|
||||
sub_str_end_pos = ustr_len;
|
||||
}
|
||||
}
|
||||
|
||||
sub_str = NULL;
|
||||
|
13
ext/intl/tests/bug55562.phpt
Normal file
13
ext/intl/tests/bug55562.phpt
Normal file
@ -0,0 +1,13 @@
|
||||
--TEST--
|
||||
grapheme_substr() - Bug55562 - grapheme_substr() returns false if length parameter is to large
|
||||
--SKIPIF--
|
||||
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(
|
||||
grapheme_substr('FOK', 1, 20), // expected: OK
|
||||
grapheme_substr('한국어', 1, 20) //expected: 국어
|
||||
);
|
||||
--EXPECT--
|
||||
string(2) "OK"
|
||||
string(6) "국어"
|
Loading…
Reference in New Issue
Block a user