summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Hirokawa <hirokawa@php.net>2002-03-16 07:13:14 +0000
committerRui Hirokawa <hirokawa@php.net>2002-03-16 07:13:14 +0000
commitc104474c3cae4a01889e364e40ab86df63ddc232 (patch)
tree79d935188b2bae43e988483925a978c336cccadf
parent0555ad1f5da33ff9debf2f65162e11bbbaa71df0 (diff)
downloadphp-git-c104474c3cae4a01889e364e40ab86df63ddc232.tar.gz
fixed errors of mbstring in regression tests.
-rw-r--r--ext/mbstring/mbstring.c89
-rw-r--r--ext/mbstring/php_mbregex.c46
-rw-r--r--ext/mbstring/tests/005.inc2
-rw-r--r--ext/mbstring/tests/006.inc1
-rw-r--r--ext/mbstring/tests/006.phpt2
-rw-r--r--ext/mbstring/tests/007.phpt2
-rw-r--r--ext/mbstring/tests/009.inc2
-rw-r--r--ext/mbstring/tests/010.inc32
-rw-r--r--ext/mbstring/tests/010.phpt24
-rw-r--r--ext/mbstring/tests/014.inc7
-rw-r--r--ext/mbstring/tests/014.phpt7
-rw-r--r--ext/mbstring/tests/016.inc12
12 files changed, 142 insertions, 84 deletions
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index c1e19b168c..bced5a83d5 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -82,8 +82,9 @@ static int php_mbstr_default_identify_list_size = sizeof(php_mbstr_default_ident
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 @@ php_mbstring_parse_encoding_list(const char *value, int value_length, int **retu
}
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 @@ php_mbstring_parse_encoding_array(zval *array, int **return_list, int *return_si
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 @@ PHP_FUNCTION(mb_substitute_character)
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 @@ PHP_FUNCTION(mb_substitute_character)
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 @@ PHP_FUNCTION(mb_strlen)
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_strlen)
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 @@ PHP_FUNCTION(mb_strpos)
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 @@ PHP_FUNCTION(mb_strpos)
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,9 +1990,19 @@ PHP_FUNCTION(mb_strimwidth)
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);
marker.val = Z_STRVAL_PP(arg4);
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c
index b71b9e4882..ecf57fa0b1 100644
--- a/ext/mbstring/php_mbregex.c
+++ b/ext/mbstring/php_mbregex.c
@@ -1,33 +1,19 @@
-/*
- * 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>
- */
-
-/*
- * PHP4 multibyte regular expression module
- * Authors:
- * 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> |
+ +----------------------------------------------------------------------+
*/
/* $Id$ */
diff --git a/ext/mbstring/tests/005.inc b/ext/mbstring/tests/005.inc
index 2aaaf8866d..5d486eb2a7 100644
--- a/ext/mbstring/tests/005.inc
+++ b/ext/mbstring/tests/005.inc
@@ -32,7 +32,7 @@ $r = mb_detect_order('BAD_NAME');
($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";
diff --git a/ext/mbstring/tests/006.inc b/ext/mbstring/tests/006.inc
index 7da2af0708..749b019990 100644
--- a/ext/mbstring/tests/006.inc
+++ b/ext/mbstring/tests/006.inc
@@ -28,6 +28,5 @@ print mb_substitute_character() . "\n";
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";
?>
diff --git a/ext/mbstring/tests/006.phpt b/ext/mbstring/tests/006.phpt
index da4f543f21..22b3e4a4fd 100644
--- a/ext/mbstring/tests/006.phpt
+++ b/ext/mbstring/tests/006.phpt
@@ -14,6 +14,6 @@ long
OK_NONE
none
== INVALID PARAMETER ==
-ERR:
+ERR: Warning
OK_BAD_NAME
diff --git a/ext/mbstring/tests/007.phpt b/ext/mbstring/tests/007.phpt
index 447243ab15..08c8b8409a 100644
--- a/ext/mbstring/tests/007.phpt
+++ b/ext/mbstring/tests/007.phpt
@@ -5,7 +5,7 @@ mb_output_handler() (EUC-JP)
--POST--
--GET--
--FILE--
-<?php include('skipif.inc'); ?>
+<?php include('007.inc'); ?>
--EXPECT--
テスト用日本語文字列。このモジュールはPHPにマルチバイト関数を提供します。
diff --git a/ext/mbstring/tests/009.inc b/ext/mbstring/tests/009.inc
index aabc8daed0..efdb9f8503 100644
--- a/ext/mbstring/tests/009.inc
+++ b/ext/mbstring/tests/009.inc
@@ -33,6 +33,7 @@ print mb_strlen($sjis) . "\n";
// 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 @@ print mb_strlen($jis) . "\n";
// 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");
diff --git a/ext/mbstring/tests/010.inc b/ext/mbstring/tests/010.inc
index f4493a5482..2f6ccc406f 100644
--- a/ext/mbstring/tests/010.inc
+++ b/ext/mbstring/tests/010.inc
@@ -26,24 +26,32 @@ print mb_strpos($euc_jp, 0, 15, 'EUC-JP') . "\n";
// 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";
diff --git a/ext/mbstring/tests/010.phpt b/ext/mbstring/tests/010.phpt
index 880176dfa3..8b3a81f8ce 100644
--- a/ext/mbstring/tests/010.phpt
+++ b/ext/mbstring/tests/010.phpt
@@ -17,14 +17,22 @@ mb_strpos()
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
diff --git a/ext/mbstring/tests/014.inc b/ext/mbstring/tests/014.inc
index 14e61633a3..afcbae28b8 100644
--- a/ext/mbstring/tests/014.inc
+++ b/ext/mbstring/tests/014.inc
@@ -11,12 +11,13 @@ print "1: ". mb_strimwidth($euc_jp, 0, 15,'...','EUC-JP') . "\n";
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";
?>
diff --git a/ext/mbstring/tests/014.phpt b/ext/mbstring/tests/014.phpt
index bc27326b32..db37e9f8bc 100644
--- a/ext/mbstring/tests/014.phpt
+++ b/ext/mbstring/tests/014.phpt
@@ -10,8 +10,11 @@ mb_strimwidth()
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
diff --git a/ext/mbstring/tests/016.inc b/ext/mbstring/tests/016.inc
index 321bbeba83..bea679e502 100644
--- a/ext/mbstring/tests/016.inc
+++ b/ext/mbstring/tests/016.inc
@@ -35,8 +35,7 @@ print("JIS: ".base64_encode($s)."\n"); // JIS
// 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 @@ print("JIS: ".base64_encode($s)."\n"); // JIS
// 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