cvs: php4(PHP_4_2_0) /ext/mbstring mbstring.c php_mbregex.c /ext/mbstring/tests 005.inc 006.inc 006.phpt 007.phpt 009.inc 010.inc 010.phpt 014.inc
014.phpt 016.inc

From: Date: Sat, 16 Mar 2002 07:13:14 +0000
Subject: cvs: php4(PHP_4_2_0) /ext/mbstring mbstring.c php_mbregex.c /ext/mbstring/tests 005.inc 006.inc 006.phpt 007.phpt 009.inc 010.inc 010.phpt 014.inc
014.phpt 016.inc
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-10212@lists.php.net to get a copy of this message
hirokawa Sat Mar 16 02:13:14 2002 EDT Modified files: (Branch: PHP_4_2_0) /php4/ext/mbstring mbstring.c php_mbregex.c /php4/ext/mbstring/tests 005.inc 006.inc 006.phpt 007.phpt 009.inc 010.inc 010.phpt 014.inc 014.phpt 016.inc Log: fixed errors of mbstring in regression tests.

Index: php4/ext/mbstring/mbstring.c diff -u php4/ext/mbstring/mbstring.c:1.48 php4/ext/mbstring/mbstring.c:1.48.2.1 --- php4/ext/mbstring/mbstring.c:1.48 Thu Feb 28 03:26:20 2002 +++ php4/ext/mbstring/mbstring.c Sat Mar 16 02:13:14 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mbstring.c,v 1.48 2002/02/28 08:26:20 sebastian Exp $ */ +/* $Id: mbstring.c,v 1.48.2.1 2002/03/16 07:13:14 hirokawa Exp $ */ /* * PHP4 Multibyte String module "mbstring" (currently only for Japanese) @@ -82,8 +82,9 @@ static unsigned char third_and_rest_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE_REST }; static unsigned char second_args_force_ref[] = { 2, BYREF_NONE, BYREF_FORCE }; +#if HAVE_MBREGEX static unsigned char third_argument_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE }; - +#endif #if defined(MBSTR_ENC_TRANS) SAPI_POST_HANDLER_FUNC(php_mbstr_post_handler); @@ -284,8 +285,13 @@ } p1 = p2 + 1; } while (n < size && p2 != NULL); - *return_list = list; - *return_size = n; + if (n > 0){ + *return_list = list; + *return_size = n; + } else { + efree(list); + *return_list = NULL; + } } efree(tmpstr); } @@ -340,8 +346,13 @@ zend_hash_move_forward(target_hash); i--; } - *return_list = list; - *return_size = n; + if (n > 0) { + *return_list = list; + *return_size = n; + } else { + efree(list); + *return_list = NULL; + } } } @@ -913,6 +924,7 @@ RETVAL_LONG(MBSTRG(current_filter_illegal_substchar)); } } else if (ZEND_NUM_ARGS() == 1 && zend_get_parameters_ex(1, &arg1) != FAILURE) { + RETVAL_TRUE; switch (Z_TYPE_PP(arg1)) { case IS_STRING: if (strcasecmp("none", Z_STRVAL_PP(arg1)) == 0) { @@ -921,17 +933,26 @@ MBSTRG(current_filter_illegal_mode) = MBFL_OUTPUTFILTER_ILLEGAL_MODE_LONG; } else { convert_to_long_ex(arg1); - MBSTRG(current_filter_illegal_mode) = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR; - MBSTRG(current_filter_illegal_substchar) = Z_LVAL_PP(arg1); + if (Z_LVAL_PP(arg1)< 0xffff && Z_LVAL_PP(arg1)> 0x0) { + MBSTRG(current_filter_illegal_mode) = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR; + MBSTRG(current_filter_illegal_substchar) = Z_LVAL_PP(arg1); + } else { + php_error(E_WARNING, "unknown character."); + RETVAL_FALSE; + } } break; default: convert_to_long_ex(arg1); - MBSTRG(current_filter_illegal_mode) = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR; - MBSTRG(current_filter_illegal_substchar) = Z_LVAL_PP(arg1); + if (Z_LVAL_PP(arg1)< 0xffff && Z_LVAL_PP(arg1)> 0x0) { + MBSTRG(current_filter_illegal_mode) = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR; + MBSTRG(current_filter_illegal_substchar) = Z_LVAL_PP(arg1); + } else { + php_error(E_WARNING, "unknown character."); + RETVAL_FALSE; + } break; } - RETVAL_TRUE; } else { WRONG_PARAM_COUNT; } @@ -1521,6 +1542,17 @@ n < 1 || n > 2) { WRONG_PARAM_COUNT; } + if (Z_TYPE_PP(arg1) == IS_ARRAY || + Z_TYPE_PP(arg1) == IS_OBJECT) { + php_error(E_NOTICE, "arg1 is invalid."); + RETURN_FALSE; + } + if (( n ==2 && Z_TYPE_PP(arg2) == IS_ARRAY) || + ( n ==2 && Z_TYPE_PP(arg2) == IS_OBJECT)) { + php_error(E_NOTICE, "arg2 is invalid."); + RETURN_FALSE; + } + convert_to_string_ex(arg1); mbfl_string_init(&string); string.no_language = MBSTRG(current_language); @@ -1553,7 +1585,7 @@ PHP_FUNCTION(mb_strpos) { pval **arg1, **arg2, **arg3, **arg4; - int offset, n; + int offset, n, reverse = 0; mbfl_string haystack, needle; mbfl_string_init(&haystack); @@ -1595,11 +1627,8 @@ convert_to_string_ex(arg1); convert_to_string_ex(arg2); - if (offset < 0) { - php_error(E_WARNING,"offset is minus value"); - offset = 0; - } - if (offset > Z_STRLEN_PP(arg1)) { + + if (offset < 0 || offset > Z_STRLEN_PP(arg1)) { php_error(E_WARNING,"offset not contained in string"); RETURN_FALSE; } @@ -1612,10 +1641,26 @@ needle.val = Z_STRVAL_PP(arg2); needle.len = Z_STRLEN_PP(arg2); - n = mbfl_strpos(&haystack, &needle, offset, 0); + n = mbfl_strpos(&haystack, &needle, offset, reverse); if (n >= 0) { RETVAL_LONG(n); } else { + switch (-n) { + case 1: + break; + case 2: + php_error(E_WARNING,"needle has not positive length."); + break; + case 4: + php_error(E_WARNING,"unknown encoding or conversion error."); + break; + case 8: + php_error(E_NOTICE,"argument is empty."); + break; + default: + php_error(E_WARNING,"unknown error in mb_strpos."); + break; + } RETVAL_FALSE; } } @@ -1945,8 +1990,18 @@ convert_to_long_ex(arg2); from = Z_LVAL_PP(arg2); + if (from < 0 || from > Z_STRLEN_PP(arg1)) { + php_error(E_WARNING,"start not contained in string"); + RETURN_FALSE; + } + convert_to_long_ex(arg3); width = Z_LVAL_PP(arg3); + + if (width < 0) { + php_error(E_WARNING,"width has negative value"); + RETURN_FALSE; + } if (ZEND_NUM_ARGS() >= 4) { convert_to_string_ex(arg4); Index: php4/ext/mbstring/php_mbregex.c diff -u php4/ext/mbstring/php_mbregex.c:1.2 php4/ext/mbstring/php_mbregex.c:1.2.2.1 --- php4/ext/mbstring/php_mbregex.c:1.2 Fri Feb 22 19:04:20 2002 +++ php4/ext/mbstring/php_mbregex.c Sat Mar 16 02:13:14 2002 @@ -1,36 +1,22 @@ -/* - * PHP3 Internationalization support program. - * - * Copyright (c) 1999,2000 by the PHP3 internationalization team. - * All rights reserved. - * - * This program is free software. You can use, redistribute and/or modify - * without fee under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY including implied or express warranty of - * marchantability or fitness for a particular purpose. - * - * Currently, the "PHP3 internationalization team" has no relationship with - * the "PHP Development Team". But we hope these code will be integrated - * into the PHP3, and it will be distributed as a part of PHP3. - * - * See README_i18n for more detail. - * - * Authors: - * Hironori Sato <satoh@jpnnet.com> - * Shigeru Kanemoto <sgk@happysize.co.jp> - * Tsukada Takuya <tsukada@fminn.nagano.nagano.jp> +/* + +----------------------------------------------------------------------+ + | PHP Version 4 | + +----------------------------------------------------------------------+ + | Copyright (c) 2001 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Tsukada Takuya <tsukada@fminn.nagano.nagano.jp> | + +----------------------------------------------------------------------+ */ -/* - * PHP4 multibyte regular expression module - * Authors: - * Tsukada Takuya <tsukada@fminn.nagano.nagano.jp> - */ - -/* $Id: php_mbregex.c,v 1.2 2002/02/23 00:04:20 hirokawa Exp $ */ +/* $Id: php_mbregex.c,v 1.2.2.1 2002/03/16 07:13:14 hirokawa Exp $ */ #ifdef HAVE_CONFIG_H Index: php4/ext/mbstring/tests/005.inc diff -u php4/ext/mbstring/tests/005.inc:1.1 php4/ext/mbstring/tests/005.inc:1.1.2.1 --- php4/ext/mbstring/tests/005.inc:1.1 Sat Mar 2 05:44:57 2002 +++ php4/ext/mbstring/tests/005.inc Sat Mar 16 02:13:14 2002 @@ -32,7 +32,7 @@ ($r === FALSE) ? print "OK_BAD_STR\n" : print "NG_BAD_STR\n"; print implode(', ', mb_detect_order()) . "\n"; -$a[] = 'BAD_NAME'; +$a = array('BAD_NAME'); $r = mb_detect_order($a); ($r === FALSE) ? print "OK_BAD_ARRAY\n" : print "NG_BAD_ARRAY\n"; print implode(', ', mb_detect_order()) . "\n"; Index: php4/ext/mbstring/tests/006.inc diff -u php4/ext/mbstring/tests/006.inc:1.1 php4/ext/mbstring/tests/006.inc:1.1.2.1 --- php4/ext/mbstring/tests/006.inc:1.1 Sat Mar 2 05:44:57 2002 +++ php4/ext/mbstring/tests/006.inc Sat Mar 16 02:13:14 2002 @@ -28,6 +28,5 @@ print "== INVALID PARAMETER ==\n"; $r = mb_substitute_character('BAD_NAME'); ($r === FALSE) ? print "OK_BAD_NAME\n" : print("NG_BAD_NAME: ".gettype($r)." $r\n"); -print mb_substitute_character() . "\n"; ?> Index: php4/ext/mbstring/tests/006.phpt diff -u php4/ext/mbstring/tests/006.phpt:1.1 php4/ext/mbstring/tests/006.phpt:1.1.2.1 --- php4/ext/mbstring/tests/006.phpt:1.1 Sat Mar 2 05:44:57 2002 +++ php4/ext/mbstring/tests/006.phpt Sat Mar 16 02:13:14 2002 @@ -14,6 +14,6 @@ OK_NONE none == INVALID PARAMETER == -ERR: +ERR: Warning OK_BAD_NAME Index: php4/ext/mbstring/tests/007.phpt diff -u php4/ext/mbstring/tests/007.phpt:1.1 php4/ext/mbstring/tests/007.phpt:1.1.2.1 --- php4/ext/mbstring/tests/007.phpt:1.1 Sat Mar 2 05:44:57 2002 +++ php4/ext/mbstring/tests/007.phpt Sat Mar 16 02:13:14 2002 @@ -5,7 +5,7 @@ --POST-- --GET-- --FILE-- -<?php include('skipif.inc'); ?> +<?php include('007.inc'); ?> --EXPECT-- ¥Æ¥¹¥ÈÍÑÆüËܸìʸ»úÎ󡣤³¤Î¥â¥¸¥å¡¼¥ë¤ÏPHP¤Ë¥Þ¥ë¥Á¥Ð¥¤¥È´Ø¿ô¤òÄ󶡤·¤Þ¤¹¡£ Index: php4/ext/mbstring/tests/009.inc diff -u php4/ext/mbstring/tests/009.inc:1.1 php4/ext/mbstring/tests/009.inc:1.1.2.1 --- php4/ext/mbstring/tests/009.inc:1.1 Sat Mar 2 05:44:57 2002 +++ php4/ext/mbstring/tests/009.inc Sat Mar 16 02:13:14 2002 @@ -33,6 +33,7 @@ // JIS // Note: either convert_encoding or strlen has problem echo "== JIS ==\n"; +mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n"); $jis = mb_convert_encoding($euc_jp, 'JIS'); print mb_strlen($jis,'JIS') . "\n"; mb_internal_encoding('JIS') or print("mb_internal_encoding() failed\n"); @@ -41,6 +42,7 @@ // UTF-8 // Note: either convert_encoding or strlen has problem echo "== UTF-8 ==\n"; +mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n"); $utf8 = mb_convert_encoding($euc_jp, 'UTF-8'); print mb_strlen($utf8,'UTF-8') . "\n"; mb_internal_encoding('UTF-8') or print("mb_internal_encoding() failed\n"); Index: php4/ext/mbstring/tests/010.inc diff -u php4/ext/mbstring/tests/010.inc:1.1 php4/ext/mbstring/tests/010.inc:1.1.2.1 --- php4/ext/mbstring/tests/010.inc:1.1 Sat Mar 2 05:44:57 2002 +++ php4/ext/mbstring/tests/010.inc Sat Mar 16 02:13:14 2002 @@ -26,24 +26,32 @@ // Note: PHP Warning - offset is negative. // Note: For offset(-15). It does not return position of latter string. (ie the same result as -50) echo "== NEGATIVE OFFSET ==\n"; -print mb_strpos($euc_jp,'ÆüËܸì', -15, 'EUC-JP') . "\n"; -print mb_strpos($euc_jp, '0', -15, 'EUC-JP') . "\n"; -print mb_strpos($euc_jp, 3, -15, 'EUC-JP') . "\n"; -print mb_strpos($euc_jp, 0, -15, 'EUC-JP') . "\n"; -print mb_strpos($euc_jp,'ÆüËܸì', -50, 'EUC-JP') . "\n"; -print mb_strpos($euc_jp, '0', -50, 'EUC-JP') . "\n"; -print mb_strpos($euc_jp, 3, -50, 'EUC-JP') . "\n"; -print mb_strpos($euc_jp, 0, -50, 'EUC-JP') . "\n"; +$r = mb_strpos($euc_jp,'ÆüËܸì', -15, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_strpos($euc_jp, '0', -15, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_strpos($euc_jp, 3, -15, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_strpos($euc_jp, 0, -15, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_strpos($euc_jp,'ÆüËܸì', -50, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_strpos($euc_jp, '0', -50, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_strpos($euc_jp, 3, -50, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_strpos($euc_jp, 0, -50, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; // Out of range - should return false print ("== OUT OF RANGE ==\n"); -$r = mb_strpos($euc_jp,'ÆüËܸì', 40, 'EUC-JP') . "\n"; +$r = mb_strpos($euc_jp,'ÆüËܸì', 40, 'EUC-JP'); ($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n"; -$r = mb_strpos($euc_jp, '0', 40, 'EUC-JP') . "\n"; +$r = mb_strpos($euc_jp, '0', 40, 'EUC-JP'); ($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n"; -$r = mb_strpos($euc_jp, 3, 40, 'EUC-JP') . "\n"; +$r = mb_strpos($euc_jp, 3, 40, 'EUC-JP'); ($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n"; -$r = mb_strpos($euc_jp, 0, 40, 'EUC-JP') . "\n"; +$r = mb_strpos($euc_jp, 0, 40, 'EUC-JP'); ($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n"; // Note: Returned NULL string // echo gettype($r). ' val '. $r ."\n"; Index: php4/ext/mbstring/tests/010.phpt diff -u php4/ext/mbstring/tests/010.phpt:1.1 php4/ext/mbstring/tests/010.phpt:1.1.2.1 --- php4/ext/mbstring/tests/010.phpt:1.1 Sat Mar 2 05:44:57 2002 +++ php4/ext/mbstring/tests/010.phpt Sat Mar 16 02:13:14 2002 @@ -17,14 +17,22 @@ 33 30 == NEGATIVE OFFSET == -34 -30 -33 -30 -10 -0 -3 -0 +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET == OUT OF RANGE == OK_OUT_RANGE OK_OUT_RANGE Index: php4/ext/mbstring/tests/014.inc diff -u php4/ext/mbstring/tests/014.inc:1.1 php4/ext/mbstring/tests/014.inc:1.1.2.1 --- php4/ext/mbstring/tests/014.inc:1.1 Sat Mar 2 05:44:57 2002 +++ php4/ext/mbstring/tests/014.inc Sat Mar 16 02:13:14 2002 @@ -11,12 +11,13 @@ print "2: ". mb_strimwidth($euc_jp, 0, 100,'...','EUC-JP') . "\n"; print "3: ". mb_strimwidth($euc_jp, 15, 100,'...','EUC-JP') . "\n"; // Note: Did not start form -22 offset. Staring from 0. -print "4: ". mb_strimwidth($euc_jp,-22, 100,'...','EUC-JP') . "\n"; +$str = mb_strimwidth($euc_jp,-22, 100,'...','EUC-JP'); +($str === FALSE) ? print "4 OK\n" : print "NG: $str\n"; $str = mb_strimwidth($euc_jp, 100, -10,'...','EUC-JP'); -($str === "") ? print "5 OK\n" : print "NG: $str\n"; +($str === FALSE) ? print "5 OK\n" : print "NG: $str\n"; $str = mb_strimwidth($euc_jp, -100, 10,'...','EUC-JP'); -($str !== "") ? print "6 OK: $str\n" : print "NG: $str\n"; +($str === FALSE) ? print "6 OK\n" : print "NG: $str\n"; ?> Index: php4/ext/mbstring/tests/014.phpt diff -u php4/ext/mbstring/tests/014.phpt:1.1 php4/ext/mbstring/tests/014.phpt:1.1.2.1 --- php4/ext/mbstring/tests/014.phpt:1.1 Sat Mar 2 05:44:57 2002 +++ php4/ext/mbstring/tests/014.phpt Sat Mar 16 02:13:14 2002 @@ -10,8 +10,11 @@ 1: 0123¤³¤Îʸ»ú... 2: 0123¤³¤Îʸ»úÎó¤ÏÆüËܸì¤Ç¤¹¡£EUC-JP¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¡£ÆüËܸì¤ÏÌÌÅݽ­¤¤¡£ 3: ¡£EUC-JP¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¡£ÆüËܸì¤ÏÌÌÅݽ­¤¤¡£ -4: EUC-JP¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¡£ÆüËܸì¤ÏÌÌÅݽ­¤¤¡£ +ERR: Warning +4 OK +ERR: Warning 5 OK -6 OK: 0123¤³... +ERR: Warning +6 OK Index: php4/ext/mbstring/tests/016.inc diff -u php4/ext/mbstring/tests/016.inc:1.1 php4/ext/mbstring/tests/016.inc:1.1.2.1 --- php4/ext/mbstring/tests/016.inc:1.1 Sat Mar 2 05:44:57 2002 +++ php4/ext/mbstring/tests/016.inc Sat Mar 16 02:13:14 2002 @@ -35,8 +35,7 @@ // Using Encoding List Array echo "== ARRAY ENCODING LIST ==\n"; -$a = array(0=>'UTF-8',1=>'EUC-JP', 2=>'SJIS', 3=>'JIS'); - +$a = array(0=>'JIS', 1=>'UTF-8', 2=>'EUC-JP', 3=>'SJIS'); $s = $jis; $s = mb_convert_encoding($s, 'EUC-JP', $a); print("EUC-JP: $s\n"); // EUC-JP @@ -53,19 +52,16 @@ // Using Detect Order echo "== DETECT ORDER ==\n"; -mb_detect_order('auto'); - - $s = $jis; -$s = mb_convert_encoding($s, 'EUC-JP'); +$s = mb_convert_encoding($s, 'EUC-JP', 'auto'); print("EUC-JP: $s\n"); // EUC-JP $s = $euc_jp; -$s = mb_convert_encoding($s, 'SJIS'); +$s = mb_convert_encoding($s, 'SJIS', 'auto'); print("SJIS: ".base64_encode($s)."\n"); // SJIS $s = $euc_jp; -$s = mb_convert_encoding($s, 'JIS'); +$s = mb_convert_encoding($s, 'JIS', 'auto'); print("JIS: ".base64_encode($s)."\n"); // JIS
« previous php.cvs (#10212) next »