fix bug 55562 - make substr always return rest of the string if length is too long

This commit is contained in:
Stanislav Malyshev 2011-09-04 18:50:05 +00:00
parent a948142d31
commit 40217d0417
2 changed files with 22 additions and 5 deletions

View File

@ -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;

View 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) "국어"