Commit: 51286bd8e5a7acd75326fae497313725e4acf234 Author: Gustavo André dos Santos Lopes <cataphr...@php.net> Wed, 23 May 2012 13:22:06 +0200 Parents: 5d61e56dd7e19b82abde23f83b203449a48cc91a Branches: PHP-5.3 PHP-5.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=51286bd8e5a7acd75326fae497313725e4acf234 Log: Fixed bug #62070 Collator::getSortKey() was returning an unterminated string due the length given to RETURN_STRINGL being off by one. Bugs: https://bugs.php.net/62070 Changed paths: M ext/intl/collator/collator_sort.c A ext/intl/tests/bug62070.phpt Diff: diff --git a/ext/intl/collator/collator_sort.c b/ext/intl/collator/collator_sort.c index a871c90..0785111 100755 --- a/ext/intl/collator/collator_sort.c +++ b/ext/intl/collator/collator_sort.c @@ -594,6 +594,8 @@ PHP_FUNCTION( collator_get_sort_key ) RETURN_FALSE; } + /* ucol_getSortKey is exception in that the key length includes the + * NUL terminator*/ key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, key, 0); if(!key_len) { efree( ustr ); @@ -605,7 +607,7 @@ PHP_FUNCTION( collator_get_sort_key ) if(!key_len) { RETURN_FALSE; } - RETURN_STRINGL((char *)key, key_len, 0); + RETURN_STRINGL((char *)key, key_len - 1, 0); } /* }}} */ diff --git a/ext/intl/tests/bug62070.phpt b/ext/intl/tests/bug62070.phpt new file mode 100644 index 0000000..a466b05 --- /dev/null +++ b/ext/intl/tests/bug62070.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #62070: Collator::getSortKey() returns garbage +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +$s1 = 'Hello'; + +$coll = collator_create('en_US'); +$res = collator_get_sort_key($coll, $s1); + +echo urlencode($res); +--EXPECT-- +5%2F%3D%3DC%01%09%01%8F%08 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php