From: Kirti Velankar Date: Mon, 27 Apr 2009 18:18:04 +0000 (+0000) Subject: Fix in grapheme_extract X-Git-Tag: php-5.3.0RC2~89 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d21456d60234144ad00b580561b7ad800056a8f3;p=php Fix in grapheme_extract --- diff --git a/ext/intl/grapheme/grapheme_string.c b/ext/intl/grapheme/grapheme_string.c index 06388e312f..edac518c6e 100755 --- a/ext/intl/grapheme/grapheme_string.c +++ b/ext/intl/grapheme/grapheme_string.c @@ -852,10 +852,11 @@ PHP_FUNCTION(grapheme_extract) */ if ( -1 != grapheme_ascii_check(pstr, size + 1 < str_len ? size + 1 : str_len ) ) { + long nsize = ( size < str_len ? size : str_len ); if ( NULL != next ) { - ZVAL_LONG(next, start+size); + ZVAL_LONG(next, start+nsize); } - RETURN_STRINGL(((char *)pstr), size, 1); + RETURN_STRINGL(((char *)pstr), nsize, 1); } /* convert the strings to UTF-16. */ diff --git a/ext/intl/tests/grapheme.phpt b/ext/intl/tests/grapheme.phpt index c9982b16f4..d65c90900d 100755 --- a/ext/intl/tests/grapheme.phpt +++ b/ext/intl/tests/grapheme.phpt @@ -560,7 +560,7 @@ function ut_main() array( "abc", 1, 1, 2, "b" ), array( "abc", 1, 2, 3, "c" ), array( "abc", 0, 2, 2, "" ), - + array( "http://news.bbc.co.uk/2/hi/middle_east/7831588.stm", 48, 48 , 50 , "tm" ), array( $char_a_ring_nfd . "bc", 3, $char_a_ring_nfd . "bc" ), array( $char_a_ring_nfd . "bc", 2, $char_a_ring_nfd . "b" ), @@ -1095,6 +1095,7 @@ extract from "abc" "1" graphemes - grapheme_extract starting at byte position 0 extract from "abc" "1" graphemes - grapheme_extract starting at byte position 1 with $next = b == b $next=2 == 2 extract from "abc" "1" graphemes - grapheme_extract starting at byte position 2 with $next = c == c $next=3 == 3 extract from "abc" "0" graphemes - grapheme_extract starting at byte position 2 with $next = == $next=2 == 2 +extract from "http%3A%2F%2Fnews.bbc.co.uk%2F2%2Fhi%2Fmiddle_east%2F7831588.stm" "48" graphemes - grapheme_extract starting at byte position 48 with $next = tm == tm $next=50 == 50 extract from "a%CC%8Abc" "3" graphemes - grapheme_extract = a%CC%8Abc == a%CC%8Abc extract from "a%CC%8Abc" "2" graphemes - grapheme_extract = a%CC%8Ab == a%CC%8Ab extract from "a%CC%8Abc" "1" graphemes - grapheme_extract = a%CC%8A == a%CC%8A