diff options
Diffstat (limited to 'ext/iconv/tests')
74 files changed, 6766 insertions, 0 deletions
diff --git a/ext/iconv/tests/Quotes.UTF-8 b/ext/iconv/tests/Quotes.UTF-8 new file mode 100644 index 0000000..3d48ee9 --- /dev/null +++ b/ext/iconv/tests/Quotes.UTF-8 @@ -0,0 +1,4 @@ +“Hello” +‘Hello’ +„Hello” +‚Hello’ diff --git a/ext/iconv/tests/bug37176.phpt b/ext/iconv/tests/bug37176.phpt new file mode 100644 index 0000000..70242fe --- /dev/null +++ b/ext/iconv/tests/bug37176.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #37176 (iconv_strpos() fails to find a string) +--SKIPIF-- +<?php +include('skipif.inc'); + +$test = @iconv_strpos("abbttt","ttt",0,"UTF-8"); +if ($test === false) { + die("skip UTF-8 is not supported?"); +} + +?> +--FILE-- +<?php +var_dump(iconv_strpos('11--','1-',0,'UTF-8')); +var_dump(iconv_strpos('-11--','1-',0,'UTF-8')); +?> +--EXPECT-- +int(1) +int(2) diff --git a/ext/iconv/tests/bug37773.phpt b/ext/iconv/tests/bug37773.phpt new file mode 100644 index 0000000..d21e6fd --- /dev/null +++ b/ext/iconv/tests/bug37773.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #37773 (iconv_substr() gives "Unknown error" when string length = 1") +--SKIPIF-- +<?php +include('skipif.inc'); + +$test = @iconv_strpos("abbttt","ttt",0,"UTF-8"); +if ($test === false) { + die("skip UTF-8 is not supported?"); +} + +?> +--FILE-- +<?php + var_dump(iconv_substr('x', 0, 1, 'UTF-8')); +?> +--EXPECT-- +string(1) "x" diff --git a/ext/iconv/tests/bug48289.phpt b/ext/iconv/tests/bug48289.phpt new file mode 100644 index 0000000..fc2cd36 --- /dev/null +++ b/ext/iconv/tests/bug48289.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #48289 (iconv_mime_encode() quoted-printable scheme is broken) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +$text = "\xE3\x83\x86\xE3\x82\xB9\xE3\x83\x88\xE3\x83\x86\xE3\x82\xB9\xE3\x83\x88"; +$options = array( + 'scheme' => 'Q', + 'input-charset' => 'UTF-8', + 'output-charset' => 'UTF-8', + 'line-length' => 30, +); + +echo iconv_mime_encode('Subject', $text, $options); +--EXPECT-- +Subject: =?UTF-8?Q?=E3=83=86?= + =?UTF-8?Q?=E3=82=B9?= + =?UTF-8?Q?=E3=83=88?= + =?UTF-8?Q?=E3=83=86?= + =?UTF-8?Q?=E3=82=B9?= + =?UTF-8?Q?=E3=83=88?= diff --git a/ext/iconv/tests/bug51250.phpt b/ext/iconv/tests/bug51250.phpt new file mode 100644 index 0000000..fd2e53b --- /dev/null +++ b/ext/iconv/tests/bug51250.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #51250 (iconv_mime_decode() does not ignore malformed Q-encoded words) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +$m = ICONV_MIME_DECODE_CONTINUE_ON_ERROR; + +var_dump(iconv_mime_decode("Legal encoded-word: =?utf-8?B?Kg==?= .", $m)); +var_dump(iconv_mime_decode("Legal encoded-word: =?utf-8?Q?*?= .", $m)); +var_dump(iconv_mime_decode("Illegal encoded-word: =?utf-8?B?".chr(0xA1)."?= .", $m)); +var_dump(iconv_mime_decode("Illegal encoded-word: =?utf-8?Q?".chr(0xA1)."?= .", $m)); + +var_dump(iconv_mime_decode("Legal encoded-word: =?utf-8?B?Kg==?= .")); +var_dump(iconv_mime_decode("Legal encoded-word: =?utf-8?Q?*?= .")); +var_dump(iconv_mime_decode("Illegal encoded-word: =?utf-8?B?".chr(0xA1)."?= .")); +var_dump(iconv_mime_decode("Illegal encoded-word: =?utf-8?Q?".chr(0xA1)."?= .")); +?> +--EXPECTF-- +string(23) "Legal encoded-word: * ." +string(23) "Legal encoded-word: * ." +string(24) "Illegal encoded-word: ." +string(23) "Illegal encoded-word: ." +string(23) "Legal encoded-word: * ." +string(23) "Legal encoded-word: * ." +string(24) "Illegal encoded-word: ." + +Notice: iconv_mime_decode(): Detected an illegal character in input string in %s on line %d +bool(false) diff --git a/ext/iconv/tests/bug52211.phpt b/ext/iconv/tests/bug52211.phpt new file mode 100644 index 0000000..c851cba --- /dev/null +++ b/ext/iconv/tests/bug52211.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #52211 (iconv() returns part of string on error) +--SKIPIF-- +<?php +include('skipif.inc'); +?> +--FILE-- +<?php + +$str = "PATHOLOGIES MÉDICO-CHIRUR. ADUL. PL"; +$str_iconv = iconv('CP850', 'ISO-8859-1', $str ); +var_dump($str_iconv); + +?> +--EXPECTF-- +Notice: iconv(): Detected an illegal character in input string in %s on line %d +bool(false) diff --git a/ext/iconv/tests/bug52941.phpt b/ext/iconv/tests/bug52941.phpt new file mode 100644 index 0000000..b336d40 --- /dev/null +++ b/ext/iconv/tests/bug52941.phpt @@ -0,0 +1,41 @@ +--TEST-- +Bug #52941 (The 'iconv_mime_decode_headers' function is skipping headers) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +$headers = <<<HEADERS +From: =?UTF-8?B?PGZvb0BleGFtcGxlLmNvbT4=?= +Subject: =?ks_c_5601-1987?B?UkU6odk=?= +X-Foo: =?ks_c_5601-1987?B?UkU6odk=?= Foo +X-Bar: =?ks_c_5601-1987?B?UkU6odk=?= =?UTF-8?Q?Foo?= +To: <test@example.com> +HEADERS; + +$decoded = iconv_mime_decode_headers($headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'); + +var_dump($decoded['From']); +var_dump($decoded['Subject']); +var_dump($decoded['X-Foo']); +var_dump($decoded['X-Bar']); +var_dump($decoded['To']); + +$decoded = iconv_mime_decode_headers($headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR | ICONV_MIME_DECODE_STRICT, 'UTF-8'); + +var_dump($decoded['From']); +var_dump($decoded['Subject']); +var_dump($decoded['X-Foo']); +var_dump($decoded['X-Bar']); +var_dump($decoded['To']); +?> +--EXPECTF-- +string(17) "<foo@example.com>" +string(%d) "%s" +string(%d) "%sFoo" +string(%d) "%sFoo" +string(18) "<test@example.com>" +string(17) "<foo@example.com>" +string(%d) "%s" +string(%d) "%sFoo" +string(%d) "%sFoo" +string(18) "<test@example.com>" diff --git a/ext/iconv/tests/bug53304.phpt b/ext/iconv/tests/bug53304.phpt new file mode 100644 index 0000000..7eb6c41 --- /dev/null +++ b/ext/iconv/tests/bug53304.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #53304 (quot_print_decode does not handle lower-case hex digits) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +echo iconv_mime_decode('=?utf-8?Q?Nachricht_=c3=bcber_Kontaktformular_www.inexio.net?=', 0, 'UTF-8') . "\n"; +echo iconv_mime_decode('=?utf-8?Q?Nachricht_=C3=BCber_Kontaktformular_www.inexio.net?=', 0, 'UTF-8') . "\n"; + +?> +--EXPECT-- +Nachricht über Kontaktformular www.inexio.net +Nachricht über Kontaktformular www.inexio.net diff --git a/ext/iconv/tests/eucjp2iso2022jp.phpt b/ext/iconv/tests/eucjp2iso2022jp.phpt new file mode 100644 index 0000000..9318c60 --- /dev/null +++ b/ext/iconv/tests/eucjp2iso2022jp.phpt @@ -0,0 +1,27 @@ +--TEST-- +EUC-JP to ISO-2022-JP +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +error_reporting=2039 +--FILE-- +<?php +/* include('test.inc'); */ +/* charset=EUC-JP */ + +function hexdump($str) { + $len = strlen($str); + for ($i = 0; $i < $len; ++$i) { + printf("%02x", ord($str{$i})); + } + print "\n"; +} + +$str = str_repeat("ܸƥȤ English text", 30); +$str .= "ܸ"; + +echo hexdump(iconv("EUC-JP", "ISO-2022-JP", $str)); +?> +--EXPECT-- +1b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c2546252d2539254824481b284220456e676c69736820746578741b2442467c4b5c386c1b2842 + diff --git a/ext/iconv/tests/eucjp2sjis.phpt b/ext/iconv/tests/eucjp2sjis.phpt new file mode 100644 index 0000000..a995125 --- /dev/null +++ b/ext/iconv/tests/eucjp2sjis.phpt @@ -0,0 +1,58 @@ +--TEST-- +EUC-JP to SJIS +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +error_reporting=2039 +--FILE-- +<?php +/* include('test.inc'); */ +/* charset=EUC-JP */ + +$str = " +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +"; + +$str = iconv("EUC-JP", "SJIS", $str); +$str = base64_encode($str); +echo $str."\n"; + +?> +--EXPECT-- +CpP6lnuM6oNlg0yDWINngsZFbmdsaXNoIFRleHQKk/qWe4zqg2WDTINYg2eCxkVuZ2xpc2ggVGV4dAqT+pZ7jOqDZYNMg1iDZ4LGRW5nbGlzaCBUZXh0CpP6lnuM6oNlg0yDWINngsZFbmdsaXNoIFRleHQKk/qWe4zqg2WDTINYg2eCxkVuZ2xpc2ggVGV4dAqT+pZ7jOqDZYNMg1iDZ4LGRW5nbGlzaCBUZXh0CpP6lnuM6oNlg0yDWINngsZFbmdsaXNoIFRleHQKk/qWe4zqg2WDTINYg2eCxkVuZ2xpc2ggVGV4dAqT+pZ7jOqDZYNMg1iDZ4LGRW5nbGlzaCBUZXh0CpP6lnuM6oNlg0yDWINngsZFbmdsaXNoIFRleHQKk/qWe4zqg2WDTINYg2eCxkVuZ2xpc2ggVGV4dAqT+pZ7jOqDZYNMg1iDZ4LGRW5nbGlzaCBUZXh0CpP6lnuM6oNlg0yDWINngsZFbmdsaXNoIFRleHQKk/qWe4zqg2WDTINYg2eCxkVuZ2xpc2ggVGV4dAqT+pZ7jOqDZYNMg1iDZ4LGRW5nbGlzaCBUZXh0CpP6lnuM6oNlg0yDWINngsZFbmdsaXNoIFRleHQKk/qWe4zqg2WDTINYg2eCxkVuZ2xpc2ggVGV4dAqT+pZ7jOqDZYNMg1iDZ4LGRW5nbGlzaCBUZXh0CpP6lnuM6oNlg0yDWINngsZFbmdsaXNoIFRleHQKk/qWe4zqg2WDTINYg2eCxkVuZ2xpc2ggVGV4dAqT+pZ7jOqDZYNMg1iDZ4LGRW5nbGlzaCBUZXh0CpP6lnuM6oNlg0yDWINngsZFbmdsaXNoIFRleHQKk/qWe4zqg2WDTINYg2eCxkVuZ2xpc2ggVGV4dAqT+pZ7jOqDZYNMg1iDZ4LGRW5nbGlzaCBUZXh0CpP6lnuM6oNlg0yDWINngsZFbmdsaXNoIFRleHQKk/qWe4zqg2WDTINYg2eCxkVuZ2xpc2ggVGV4dAqT+pZ7jOqDZYNMg1iDZ4LGRW5nbGlzaCBUZXh0CpP6lnuM6oNlg0yDWINngsZFbmdsaXNoIFRleHQKk/qWe4zqg2WDTINYg2eCxkVuZ2xpc2ggVGV4dAqT+pZ7jOqDZYNMg1iDZ4LGRW5nbGlzaCBUZXh0CpP6lnuM6oNlg0yDWINngsZFbmdsaXNoIFRleHQKk/qWe4zqg2WDTINYg2eCxkVuZ2xpc2ggVGV4dAqT+pZ7jOqDZYNMg1iDZ4LGRW5nbGlzaCBUZXh0CpP6lnuM6oNlg0yDWINngsZFbmdsaXNoIFRleHQKk/qWe4zqg2WDTINYg2eCxkVuZ2xpc2ggVGV4dAqT+pZ7jOqDZYNMg1iDZ4LGRW5nbGlzaCBUZXh0Cg== + diff --git a/ext/iconv/tests/eucjp2utf8.phpt b/ext/iconv/tests/eucjp2utf8.phpt new file mode 100644 index 0000000..4ffcfef --- /dev/null +++ b/ext/iconv/tests/eucjp2utf8.phpt @@ -0,0 +1,58 @@ +--TEST-- +EUC-JP to UTF8 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +error_reporting=2039 +--FILE-- +<?php +/* include('test.inc'); */ +/* charset=EUC-JP */ + +$str = " +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +ܸƥȤEnglish Text +"; + +$str = iconv("EUC-JP", "UTF-8", $str); /* libiconv(1.8) doesn't know "UTF8" but "UTF-8". */ +$str = base64_encode($str); +echo $str."\n"; + +?> +--EXPECT-- +CuaXpeacrOiqnuODhuOCreOCueODiOOBqEVuZ2xpc2ggVGV4dArml6XmnKzoqp7jg4bjgq3jgrnjg4jjgahFbmdsaXNoIFRleHQK5pel5pys6Kqe44OG44Kt44K544OI44GoRW5nbGlzaCBUZXh0CuaXpeacrOiqnuODhuOCreOCueODiOOBqEVuZ2xpc2ggVGV4dArml6XmnKzoqp7jg4bjgq3jgrnjg4jjgahFbmdsaXNoIFRleHQK5pel5pys6Kqe44OG44Kt44K544OI44GoRW5nbGlzaCBUZXh0CuaXpeacrOiqnuODhuOCreOCueODiOOBqEVuZ2xpc2ggVGV4dArml6XmnKzoqp7jg4bjgq3jgrnjg4jjgahFbmdsaXNoIFRleHQK5pel5pys6Kqe44OG44Kt44K544OI44GoRW5nbGlzaCBUZXh0CuaXpeacrOiqnuODhuOCreOCueODiOOBqEVuZ2xpc2ggVGV4dArml6XmnKzoqp7jg4bjgq3jgrnjg4jjgahFbmdsaXNoIFRleHQK5pel5pys6Kqe44OG44Kt44K544OI44GoRW5nbGlzaCBUZXh0CuaXpeacrOiqnuODhuOCreOCueODiOOBqEVuZ2xpc2ggVGV4dArml6XmnKzoqp7jg4bjgq3jgrnjg4jjgahFbmdsaXNoIFRleHQK5pel5pys6Kqe44OG44Kt44K544OI44GoRW5nbGlzaCBUZXh0CuaXpeacrOiqnuODhuOCreOCueODiOOBqEVuZ2xpc2ggVGV4dArml6XmnKzoqp7jg4bjgq3jgrnjg4jjgahFbmdsaXNoIFRleHQK5pel5pys6Kqe44OG44Kt44K544OI44GoRW5nbGlzaCBUZXh0CuaXpeacrOiqnuODhuOCreOCueODiOOBqEVuZ2xpc2ggVGV4dArml6XmnKzoqp7jg4bjgq3jgrnjg4jjgahFbmdsaXNoIFRleHQK5pel5pys6Kqe44OG44Kt44K544OI44GoRW5nbGlzaCBUZXh0CuaXpeacrOiqnuODhuOCreOCueODiOOBqEVuZ2xpc2ggVGV4dArml6XmnKzoqp7jg4bjgq3jgrnjg4jjgahFbmdsaXNoIFRleHQK5pel5pys6Kqe44OG44Kt44K544OI44GoRW5nbGlzaCBUZXh0CuaXpeacrOiqnuODhuOCreOCueODiOOBqEVuZ2xpc2ggVGV4dArml6XmnKzoqp7jg4bjgq3jgrnjg4jjgahFbmdsaXNoIFRleHQK5pel5pys6Kqe44OG44Kt44K544OI44GoRW5nbGlzaCBUZXh0CuaXpeacrOiqnuODhuOCreOCueODiOOBqEVuZ2xpc2ggVGV4dArml6XmnKzoqp7jg4bjgq3jgrnjg4jjgahFbmdsaXNoIFRleHQK5pel5pys6Kqe44OG44Kt44K544OI44GoRW5nbGlzaCBUZXh0CuaXpeacrOiqnuODhuOCreOCueODiOOBqEVuZ2xpc2ggVGV4dArml6XmnKzoqp7jg4bjgq3jgrnjg4jjgahFbmdsaXNoIFRleHQK5pel5pys6Kqe44OG44Kt44K544OI44GoRW5nbGlzaCBUZXh0CuaXpeacrOiqnuODhuOCreOCueODiOOBqEVuZ2xpc2ggVGV4dArml6XmnKzoqp7jg4bjgq3jgrnjg4jjgahFbmdsaXNoIFRleHQK5pel5pys6Kqe44OG44Kt44K544OI44GoRW5nbGlzaCBUZXh0Cg== + diff --git a/ext/iconv/tests/iconv-charset-length-cve-2007-4840.phpt b/ext/iconv/tests/iconv-charset-length-cve-2007-4840.phpt new file mode 100644 index 0000000..03b3574 --- /dev/null +++ b/ext/iconv/tests/iconv-charset-length-cve-2007-4840.phpt @@ -0,0 +1,17 @@ +--TEST-- +iconv() charset parameter length checks (CVE-2007-4840) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +$a = str_repeat("/", 9000000); +var_dump(iconv($a, "b", "test")); +var_dump(iconv("x", $a, "test")); +?> +--EXPECTF-- + +Warning: iconv(): Charset parameter exceeds the maximum allowed length of %d characters in %s on line %d +bool(false) + +Warning: iconv(): Charset parameter exceeds the maximum allowed length of %d characters in %s on line %d +bool(false) diff --git a/ext/iconv/tests/iconv001.phpt b/ext/iconv/tests/iconv001.phpt new file mode 100644 index 0000000..3ef4924 --- /dev/null +++ b/ext/iconv/tests/iconv001.phpt @@ -0,0 +1,18 @@ +--TEST-- +iconv() test 1 +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +error_reporting=2039 +--FILE-- +<?php +/* include('test.inc'); */ +echo "iconv extension is available\n"; +$test = ""; +var_dump("ISO-8859-1: $test"); +var_dump("UTF-8: ".iconv( "ISO-8859-1", "UTF-8", $test ) ); +?> +--EXPECT-- +iconv extension is available +string(15) "ISO-8859-1: " +string(13) "UTF-8: æøå" diff --git a/ext/iconv/tests/iconv002.phpt b/ext/iconv/tests/iconv002.phpt new file mode 100644 index 0000000..034b376 --- /dev/null +++ b/ext/iconv/tests/iconv002.phpt @@ -0,0 +1,30 @@ +--TEST-- +iconv() test 2 (UCS4BE to ASCII) +--SKIPIF-- +<?php +include('skipif.inc'); +if (@iconv("ascii","UCS-4LE", "abcd") == '') { + die("skip conversion to UCS-4LE not supported"); +} +?> +--INI-- +error_reporting=2039 +--FILE-- +<?php +/* include('test.inc'); */ +/* +Expected output: +abcd +abcd +*/ + + $s = unpack("V*", iconv("ascii","UCS-4LE", "abcd")); + foreach($s as $c) { print "&#$c;"; } print "\n"; + + $s = pack("NNNN", 97, 98, 99, 100); + $q = iconv("UCS-4BE", "ascii", $s); + print $q; print "\n"; +?> +--EXPECT-- +abcd +abcd diff --git a/ext/iconv/tests/iconv003.phpt b/ext/iconv/tests/iconv003.phpt new file mode 100644 index 0000000..9642cf1 --- /dev/null +++ b/ext/iconv/tests/iconv003.phpt @@ -0,0 +1,15 @@ +--TEST-- +iconv() test 3 +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +for ($i = 0; $i < 3; ++$i) { + if (@iconv('blah', 'blah', 'blah') != '') { + die("failed\n"); + } +} +echo "success\n"; +?> +--EXPECT-- +success diff --git a/ext/iconv/tests/iconv004.phpt b/ext/iconv/tests/iconv004.phpt new file mode 100644 index 0000000..6c86065 --- /dev/null +++ b/ext/iconv/tests/iconv004.phpt @@ -0,0 +1,16 @@ +--TEST-- +iconv_mime_encode() sanity cheeck. +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--INI-- +iconv.input_encoding = ISO-8859-1 +iconv.internal_encoding = ISO-8859-1 +iconv.output_encoding = ISO-8859-1 +--FILE-- +<?php +var_dump(iconv_mime_encode('', '')); +var_dump(iconv_mime_encode('', '', array('line-break-chars' => 1))); +?> +--EXPECT-- +string(19) ": =?ISO-8859-1?B??=" +string(19) ": =?ISO-8859-1?B??=" diff --git a/ext/iconv/tests/iconv_basic.phpt b/ext/iconv/tests/iconv_basic.phpt new file mode 100644 index 0000000..e0e2cb2 --- /dev/null +++ b/ext/iconv/tests/iconv_basic.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test iconv() function : basic functionality +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv') or die("skip iconv() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : string iconv(string in_charset, string out_charset, string str) + * Description: Returns converted string in desired encoding + * Source code: ext/iconv/iconv.c + */ + +/* + * Test basic functionality of iconv() + */ + +echo "*** Testing iconv() : basic functionality ***\n"; + +//All strings are the same when displayed in their respective encodings +$sjis_string = base64_decode(b'k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=='); +$euc_jp_string = base64_decode(b'xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=='); +$utf8_string = base64_decode(b'5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); + +echo "\n-- Convert to EUC-JP --\n"; +echo "Expected EUC-JP encoded string in base64:\n"; +var_dump(bin2hex($euc_jp_string)); +echo "Converted Strings:\n"; +var_dump(bin2hex(iconv('SJIS', 'EUC-JP', $sjis_string ))); +var_dump(bin2hex(iconv('UTF-8', 'EUC-JP', $utf8_string))); + +echo "\n-- Convert to SJIS --\n"; +echo "Expected SJIS encoded string in base64:\n"; +var_dump(bin2hex($sjis_string)); +echo "Converted Strings:\n"; +var_dump(bin2hex(iconv('EUC-JP', 'SJIS', $euc_jp_string))); +var_dump(bin2hex(iconv('UTF-8', 'SJIS', $utf8_string))); + +echo "\n-- Convert to UTF-8 --\n"; +echo "Expected UTF-8 encoded string in base64:\n"; +var_dump(bin2hex($utf8_string)); +echo "Converted Strings:\n"; +var_dump(bin2hex(iconv('SJIS', 'UTF-8', $sjis_string))); +var_dump(bin2hex(iconv('EUC-JP', 'UTF-8', $euc_jp_string))); + +echo "Done"; +?> +--EXPECT-- +*** Testing iconv() : basic functionality *** + +-- Convert to EUC-JP -- +Expected EUC-JP encoded string in base64: +string(74) "c6fccbdcb8eca5c6a5ada5b9a5c8a4c7a4b9a1a33031323334a3b5a3b6a3b7a3b8a3b9a1a3" +Converted Strings: +string(74) "c6fccbdcb8eca5c6a5ada5b9a5c8a4c7a4b9a1a33031323334a3b5a3b6a3b7a3b8a3b9a1a3" +string(74) "c6fccbdcb8eca5c6a5ada5b9a5c8a4c7a4b9a1a33031323334a3b5a3b6a3b7a3b8a3b9a1a3" + +-- Convert to SJIS -- +Expected SJIS encoded string in base64: +string(74) "93fa967b8cea8365834c8358836782c582b781423031323334825482558256825782588142" +Converted Strings: +string(74) "93fa967b8cea8365834c8358836782c582b781423031323334825482558256825782588142" +string(74) "93fa967b8cea8365834c8358836782c582b781423031323334825482558256825782588142" + +-- Convert to UTF-8 -- +Expected UTF-8 encoded string in base64: +string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082" +Converted Strings: +string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082" +string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082" +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_encoding_basic.phpt b/ext/iconv/tests/iconv_encoding_basic.phpt new file mode 100644 index 0000000..7468581 --- /dev/null +++ b/ext/iconv/tests/iconv_encoding_basic.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test iconv_get_encoding()/iconv_set_encoding() function : basic functionality +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_get_encoding') or die("skip iconv_get_encoding() is not available in this build"); +?> +--INI-- +iconv.input_encoding=ISO-8859-1 +iconv.internal_encoding=ISO-8859-1 +iconv.output_encoding=ISO-8859-1 +--FILE-- +<?php +/* Prototype : mixed iconv_get_encoding([string type]) + * Description: Get internal encoding and output encoding for ob_iconv_handler() + * Prototype : bool iconv_set_encoding(string type, string charset) + * Description: Sets internal encoding and output encoding for ob_iconv_handler() + * Source code: ext/iconv/iconv.c + */ + +/* + * Test Basic functionality of iconv_get_encoding/iconv_set_encoding + */ + +echo "*** Testing iconv_get_encoding()/iconv_set_encoding() : basic functionality ***\n"; + +echo "--- Default get_encoding ---\n"; +var_dump(iconv_get_encoding()); +var_dump(iconv_get_encoding("input_encoding")); +var_dump(iconv_get_encoding("output_encoding")); +var_dump(iconv_get_encoding("internal_encoding")); +var_dump(iconv_get_encoding("all")); + +echo "\n--- Altering encodings ---\n"; +var_dump(iconv_set_encoding("input_encoding", "UTF-8")); +var_dump(iconv_set_encoding("output_encoding", "UTF-8")); +var_dump(iconv_set_encoding("internal_encoding", "UTF-8")); + + +echo "\n--- results of alterations ---\n"; +var_dump(iconv_get_encoding()); +var_dump(iconv_get_encoding("input_encoding")); +var_dump(iconv_get_encoding("output_encoding")); +var_dump(iconv_get_encoding("internal_encoding")); +var_dump(iconv_get_encoding("all")); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_get_encoding()/iconv_set_encoding() : basic functionality *** +--- Default get_encoding --- +array(3) { + ["input_encoding"]=> + string(10) "ISO-8859-1" + ["output_encoding"]=> + string(10) "ISO-8859-1" + ["internal_encoding"]=> + string(10) "ISO-8859-1" +} +string(10) "ISO-8859-1" +string(10) "ISO-8859-1" +string(10) "ISO-8859-1" +array(3) { + ["input_encoding"]=> + string(10) "ISO-8859-1" + ["output_encoding"]=> + string(10) "ISO-8859-1" + ["internal_encoding"]=> + string(10) "ISO-8859-1" +} + +--- Altering encodings --- +bool(true) +bool(true) +bool(true) + +--- results of alterations --- +array(3) { + ["input_encoding"]=> + string(5) "UTF-8" + ["output_encoding"]=> + string(5) "UTF-8" + ["internal_encoding"]=> + string(5) "UTF-8" +} +string(5) "UTF-8" +string(5) "UTF-8" +string(5) "UTF-8" +array(3) { + ["input_encoding"]=> + string(5) "UTF-8" + ["output_encoding"]=> + string(5) "UTF-8" + ["internal_encoding"]=> + string(5) "UTF-8" +} +Done diff --git a/ext/iconv/tests/iconv_get_encoding_basic.phpt b/ext/iconv/tests/iconv_get_encoding_basic.phpt new file mode 100644 index 0000000..83efd15 --- /dev/null +++ b/ext/iconv/tests/iconv_get_encoding_basic.phpt @@ -0,0 +1,76 @@ +--TEST-- +iconv_get_encoding() parameter tests +--CREDITS-- +Oystein Rose <orose@redpill-linpro.com> +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- +<?php if (!extension_loaded("iconv")) { echo 'skip extension not available'; } ?> +--FILE-- +<?php + +iconv_set_encoding("internal_encoding", "UTF-8"); +iconv_set_encoding("output_encoding", "UTF-8"); +iconv_set_encoding("input_encoding", "UTF-8"); + +var_dump( iconv_get_encoding('internal_encoding') ); +var_dump( iconv_get_encoding('output_encoding') ); +var_dump( iconv_get_encoding('input_encoding') ); +var_dump( iconv_get_encoding('all') ); +var_dump( iconv_get_encoding('foo') ); +var_dump( iconv_get_encoding() ); + + + +iconv_set_encoding("internal_encoding", "ISO-8859-1"); +iconv_set_encoding("output_encoding", "ISO-8859-1"); +iconv_set_encoding("input_encoding", "ISO-8859-1"); + +var_dump( iconv_get_encoding('internal_encoding') ); +var_dump( iconv_get_encoding('output_encoding') ); +var_dump( iconv_get_encoding('input_encoding') ); +var_dump( iconv_get_encoding('all') ); +var_dump( iconv_get_encoding('foo') ); +var_dump( iconv_get_encoding() ); + +?> +--EXPECT-- +string(5) "UTF-8" +string(5) "UTF-8" +string(5) "UTF-8" +array(3) { + ["input_encoding"]=> + string(5) "UTF-8" + ["output_encoding"]=> + string(5) "UTF-8" + ["internal_encoding"]=> + string(5) "UTF-8" +} +bool(false) +array(3) { + ["input_encoding"]=> + string(5) "UTF-8" + ["output_encoding"]=> + string(5) "UTF-8" + ["internal_encoding"]=> + string(5) "UTF-8" +} +string(10) "ISO-8859-1" +string(10) "ISO-8859-1" +string(10) "ISO-8859-1" +array(3) { + ["input_encoding"]=> + string(10) "ISO-8859-1" + ["output_encoding"]=> + string(10) "ISO-8859-1" + ["internal_encoding"]=> + string(10) "ISO-8859-1" +} +bool(false) +array(3) { + ["input_encoding"]=> + string(10) "ISO-8859-1" + ["output_encoding"]=> + string(10) "ISO-8859-1" + ["internal_encoding"]=> + string(10) "ISO-8859-1" +} diff --git a/ext/iconv/tests/iconv_get_encoding_error.phpt b/ext/iconv/tests/iconv_get_encoding_error.phpt new file mode 100644 index 0000000..b0c3e07 --- /dev/null +++ b/ext/iconv/tests/iconv_get_encoding_error.phpt @@ -0,0 +1,177 @@ +--TEST-- +Test iconv_get_encoding() function : basic functionality +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_get_encoding') or die("skip iconv_get_encoding() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : mixed iconv_get_encoding([string type]) + * Description: Get internal encoding and output encoding for ob_iconv_handler() + * Source code: ext/iconv/iconv.c + */ + +/* + * Test Error functionality of iconv_get_encoding + */ + +echo "*** Testing iconv_get_encoding() : error functionality ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "UTF-8"; + } +} + +// heredoc string +$heredoc = <<<EOT +Nothing +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $encoding argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of mb_regex_encoding() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_get_encoding($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_get_encoding() : error functionality *** + +-- Iteration 1 -- +bool(false) + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- +bool(false) + +-- Iteration 20 -- +bool(false) + +-- Iteration 21 -- +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- + +Warning: iconv_get_encoding() expects parameter 1 to be string, resource given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_mime_decode-charset-length-cve-2007-4840.phpt b/ext/iconv/tests/iconv_mime_decode-charset-length-cve-2007-4840.phpt new file mode 100644 index 0000000..d4ed01d --- /dev/null +++ b/ext/iconv/tests/iconv_mime_decode-charset-length-cve-2007-4840.phpt @@ -0,0 +1,13 @@ +--TEST-- +iconv_mime_decode() charset parameter length checks (CVE-2007-4840) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +$a = str_repeat("/", 9000000); +var_dump(iconv_mime_decode("a", null, $a)); +?> +--EXPECTF-- + +Warning: iconv_mime_decode(): Charset parameter exceeds the maximum allowed length of %d characters in %s on line %d +bool(false) diff --git a/ext/iconv/tests/iconv_mime_decode.phpt b/ext/iconv/tests/iconv_mime_decode.phpt new file mode 100644 index 0000000..24d1794 --- /dev/null +++ b/ext/iconv/tests/iconv_mime_decode.phpt @@ -0,0 +1,90 @@ +--TEST-- +iconv_mime_decode() +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--INI-- +iconv.internal_charset=iso-8859-1 +--FILE-- +<?php +function my_error_handler($errno, $errmsg, $filename, $linenum, $vars) +{ + echo "$errno: $errmsg\n"; +} +set_error_handler('my_error_handler'); + +function do_single_test($header) +{ + global $mode; + + $result = iconv_mime_decode($header, $mode, "UTF-8"); + printf("(%d) \"%s\"\n", iconv_strlen($result, "UTF-8"), $result); +} + +function do_regression_test() +{ + do_single_test(<<< HERE +Subject: =?ISO-8859-1?Q?Pr=FCfung?= + =?ISO-8859-1*de_DE?Q?Pr=FCfung?=\t + =?ISO-8859-2?Q?k=F9=D4=F1=D3let?= +HERE +); + do_single_test(<<< HERE +Subject: =?ISO-8859-1?Q?Pr=FCfung?= =?ISO-8859-1*de_DE?Q?=20Pr=FCfung?= \t =?ISO-8859-2?Q?k=F9=D4=F1=D3let?= +HERE +); + do_single_test(<<< HERE +Subject: =?ISO-8859-1?Q?Pr=FCfung?==?ISO-8859-1*de_DE?Q?Pr=FCfung?==?ISO-8859-2?Q?k=F9=D4=F1=D3let?= +HERE +); + do_single_test(<<< HERE +Subject: =?ISO-8859-1?Q?Pr=FCfung?= =?ISO-8859-1*de_DE?Q?Pr=FCfung?? =?ISO-8859-2?X?k=F9=D4=F1=D3let?= +HERE +); + do_single_test(<<< HERE +From: =?ISO-2022-JP?B?GyRCJTUbKEI=?= + =?ISO-2022-JP?B?GyRCJXMlVxsoQg==?= + =?ISO-2022-JP?B?GyRCJWtKOBsoQg==?= + =?ISO-2022-JP?B?GyRCO3pOcxsoQg==?= + =?ISO-2022-JP?B?GyRCJTUlcxsoQg==?= + =?ISO-2022-JP?B?GyRCJVclaxsoQg==?= + =?ISO-2022-JP?B?GyRCSjg7ehsoQg==?= + =?ISO-2022-JP?B?GyRCTnNGfBsoQg==?= + =?ISO-2022-JP?B?GyRCS1w4bBsoQg==?= + =?ISO-2022-JP?B?GyRCJUYlLRsoQg==?= + =?ISO-2022-JP?B?GyRCJTklSBsoQg==?= +HERE +); +} + +$mode = 0; +do_regression_test(); +$mode = ICONV_MIME_DECODE_STRICT; +do_regression_test(); +$mode = ICONV_MIME_DECODE_CONTINUE_ON_ERROR; +do_regression_test(); +$mode = ICONV_MIME_DECODE_STRICT | ICONV_MIME_DECODE_CONTINUE_ON_ERROR; +do_regression_test(); +--EXPECT-- +(31) "Subject: PrüfungPrüfungkůÔńÓlet" +(32) "Subject: Prüfung PrüfungkůÔńÓlet" +(31) "Subject: PrüfungPrüfungkůÔńÓlet" +2: iconv_mime_decode(): Malformed string +(0) "" +(27) "From: サンプル文字列サンプル文字列日本語テキスト" +(31) "Subject: PrüfungPrüfungkůÔńÓlet" +(32) "Subject: Prüfung PrüfungkůÔńÓlet" +(100) "Subject: =?ISO-8859-1?Q?Pr=FCfung?==?ISO-8859-1*de_DE?Q?Pr=FCfung?==?ISO-8859-2?Q?k=F9=D4=F1=D3let?=" +2: iconv_mime_decode(): Malformed string +(0) "" +(27) "From: サンプル文字列サンプル文字列日本語テキスト" +(31) "Subject: PrüfungPrüfungkůÔńÓlet" +(32) "Subject: Prüfung PrüfungkůÔńÓlet" +(31) "Subject: PrüfungPrüfungkůÔńÓlet" +(84) "Subject: Prüfung=?ISO-8859-1*de_DE?Q?Pr=FCfung?? =?ISO-8859-2?X?k=F9=D4=F1=D3let?=" +(27) "From: サンプル文字列サンプル文字列日本語テキスト" +(31) "Subject: PrüfungPrüfungkůÔńÓlet" +(32) "Subject: Prüfung PrüfungkůÔńÓlet" +(100) "Subject: =?ISO-8859-1?Q?Pr=FCfung?==?ISO-8859-1*de_DE?Q?Pr=FCfung?==?ISO-8859-2?Q?k=F9=D4=F1=D3let?=" +(84) "Subject: Prüfung=?ISO-8859-1*de_DE?Q?Pr=FCfung?? =?ISO-8859-2?X?k=F9=D4=F1=D3let?=" +(27) "From: サンプル文字列サンプル文字列日本語テキスト" + diff --git a/ext/iconv/tests/iconv_mime_decode_headers-charset-length-cve-2007-4840.phpt b/ext/iconv/tests/iconv_mime_decode_headers-charset-length-cve-2007-4840.phpt new file mode 100644 index 0000000..48d664d --- /dev/null +++ b/ext/iconv/tests/iconv_mime_decode_headers-charset-length-cve-2007-4840.phpt @@ -0,0 +1,13 @@ +--TEST-- +iconv_mime_decode_headers() charset parameter length checks (CVE-2007-4840) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +$a = str_repeat("/", 9000000); +var_dump(iconv_mime_decode_headers("a", null, $a)); +?> +--EXPECTF-- + +Warning: iconv_mime_decode_headers(): Charset parameter exceeds the maximum allowed length of %d characters in %s on line %d +bool(false) diff --git a/ext/iconv/tests/iconv_mime_decode_headers.phpt b/ext/iconv/tests/iconv_mime_decode_headers.phpt new file mode 100644 index 0000000..71431f7 --- /dev/null +++ b/ext/iconv/tests/iconv_mime_decode_headers.phpt @@ -0,0 +1,89 @@ +--TEST-- +iconv_mime_decode_headers() +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--INI-- +iconv.internal_charset=iso-8859-1 +--FILE-- +<?php +$headers = <<<HERE +Return-Path: <internals-return-5651-***=***.example.com@lists.php.net> +Received: from pb1.pair.com (pb1.pair.com [16.92.131.4]) by ***.example.com + (8.12.10/8.12.10/1970-09-30) with SMTP id hALLmpea023899 for + <***@***.example.com>; Sat, 22 Jan 1970 06:48:51 +0900 (JST) + (envelope-from + internals-return-5651-***=***.example.com@lists.php.net) +Received: (qmail 63472 invoked by uid 1010); 1 Jan 1970 0:00:00 -0000 +Mailing-List: contact internals-help@lists.php.net; run by ezmlm +Precedence: bulk +List-Help: <mailto:internals-help@lists.php.net> +List-Unsubscribe: <mailto:internals-unsubscribe@lists.php.net> +List-Post: <mailto:internals@lists.php.net> +Delivered-To: mailing list internals@lists.php.net +Received: (qmail 63459 invoked by uid 1010); 1 Jan 1970 0:00:00 -0000 +Delivered-To: ezmlm-scan-internals@lists.php.net +Delivered-To: ezmlm-internals@lists.php.net +Date: Thu, 1 Jan 1970 00:00:00 -0000 (GMT) +From: *** *** *** <***@***.example.com> +X-X-Sender: ***@***.example.com +To: internals@lists.php.net +Message-Id: <Pine.LNX.4.58.************@***.example.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +Subject: [PHP-DEV] [ICONV] test for =?US-ASCII?Q?iconv_mime_decode_headers=28=29?= +X-UIDL: @eH!!h2:!!EOS!!A_c"! +HERE; +var_dump(iconv_mime_decode_headers($headers)); +?> +--EXPECT-- +array(17) { + ["Return-Path"]=> + string(57) "<internals-return-5651-***=***.example.com@lists.php.net>" + ["Received"]=> + array(3) { + [0]=> + string(259) "from pb1.pair.com (pb1.pair.com [16.92.131.4]) by ***.example.com (8.12.10/8.12.10/1970-09-30) with SMTP id hALLmpea023899 for <***@***.example.com>; Sat, 22 Jan 1970 06:48:51 +0900 (JST) (envelope-from internals-return-5651-***=***.example.com@lists.php.net)" + [1]=> + string(59) "(qmail 63472 invoked by uid 1010); 1 Jan 1970 0:00:00 -0000" + [2]=> + string(59) "(qmail 63459 invoked by uid 1010); 1 Jan 1970 0:00:00 -0000" + } + ["Mailing-List"]=> + string(50) "contact internals-help@lists.php.net; run by ezmlm" + ["Precedence"]=> + string(4) "bulk" + ["List-Help"]=> + string(37) "<mailto:internals-help@lists.php.net>" + ["List-Unsubscribe"]=> + string(44) "<mailto:internals-unsubscribe@lists.php.net>" + ["List-Post"]=> + string(32) "<mailto:internals@lists.php.net>" + ["Delivered-To"]=> + array(3) { + [0]=> + string(36) "mailing list internals@lists.php.net" + [1]=> + string(34) "ezmlm-scan-internals@lists.php.net" + [2]=> + string(29) "ezmlm-internals@lists.php.net" + } + ["Date"]=> + string(36) "Thu, 1 Jan 1970 00:00:00 -0000 (GMT)" + ["From"]=> + string(33) "*** *** *** <***@***.example.com>" + ["X-X-Sender"]=> + string(19) "***@***.example.com" + ["To"]=> + string(23) "internals@lists.php.net" + ["Message-Id"]=> + string(44) "<Pine.LNX.4.58.************@***.example.com>" + ["MIME-Version"]=> + string(3) "1.0" + ["Content-Type"]=> + string(28) "TEXT/PLAIN; charset=US-ASCII" + ["Subject"]=> + string(54) "[PHP-DEV] [ICONV] test for iconv mime decode headers()" + ["X-UIDL"]=> + string(20) "@eH!!h2:!!EOS!!A_c"!" +} + diff --git a/ext/iconv/tests/iconv_mime_decode_headers_variation1.phpt b/ext/iconv/tests/iconv_mime_decode_headers_variation1.phpt new file mode 100644 index 0000000..7cc32c7 --- /dev/null +++ b/ext/iconv/tests/iconv_mime_decode_headers_variation1.phpt @@ -0,0 +1,218 @@ +--TEST-- +Test iconv_mime_encode() function : usage variations - Pass different data types to headers arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_mime_decode_headers') or die("skip iconv_mime_decode_headers() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : array iconv_mime_decode_headers(string headers [, int mode, string charset]) + * Description: Decodes multiple mime header fields + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass different data types to $str argument to see how iconv_mime_decode_headers() behaves + */ + +echo "*** Testing iconv_mime_decode_headers() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$headers = <<<EOF +Subject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?= +To: example@example.com +Date: Thu, 1 Jan 1970 00:00:00 +0000 +Message-Id: <example@example.com> +Received: from localhost (localhost [127.0.0.1]) by localhost + with SMTP id example for <example@example.com>; + Thu, 1 Jan 1970 00:00:00 +0000 (UTC) + (envelope-from example-return-0000-example=example.com@example.com) +Received: (qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000 + +EOF; + +$mode = ICONV_MIME_DECODE_CONTINUE_ON_ERROR; +$charset = 'ISO-8859-1'; + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $str argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_mime_decode_headers() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_mime_decode_headers($input, $mode, $charset)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_mime_decode_headers() : usage variations *** + +-- Iteration 1 -- +array(0) { +} + +-- Iteration 2 -- +array(0) { +} + +-- Iteration 3 -- +array(0) { +} + +-- Iteration 4 -- +array(0) { +} + +-- Iteration 5 -- +array(0) { +} + +-- Iteration 6 -- +array(0) { +} + +-- Iteration 7 -- +array(0) { +} + +-- Iteration 8 -- +array(0) { +} + +-- Iteration 9 -- +array(0) { +} + +-- Iteration 10 -- +array(0) { +} + +-- Iteration 11 -- +array(0) { +} + +-- Iteration 12 -- +array(0) { +} + +-- Iteration 13 -- +array(0) { +} + +-- Iteration 14 -- +array(0) { +} + +-- Iteration 15 -- +array(0) { +} + +-- Iteration 16 -- +array(0) { +} + +-- Iteration 17 -- +array(0) { +} + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- +array(0) { +} + +-- Iteration 20 -- +array(0) { +} + +-- Iteration 21 -- +array(0) { +} + +-- Iteration 22 -- +array(0) { +} + +-- Iteration 23 -- +array(0) { +} + +-- Iteration 24 -- + +Warning: iconv_mime_decode_headers() expects parameter 1 to be string, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_mime_decode_headers_variation2.phpt b/ext/iconv/tests/iconv_mime_decode_headers_variation2.phpt new file mode 100644 index 0000000..5ceb801 --- /dev/null +++ b/ext/iconv/tests/iconv_mime_decode_headers_variation2.phpt @@ -0,0 +1,479 @@ +--TEST-- +Test iconv_mime_encode() function : usage variations - Pass different data types to mode arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_mime_decode_headers') or die("skip iconv_mime_decode_headers() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : array iconv_mime_decode_headers(string headers [, int mode, string charset]) + * Description: Decodes multiple mime header fields + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass different data types to $str argument to see how iconv_mime_decode_headers() behaves + */ + +echo "*** Testing iconv_mime_decode_headers() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$headers = <<<EOF +Subject: =?UTF-8?B?QSBTYW1wbGUgVGVzdA==?= +To: example@example.com +Date: Thu, 1 Jan 1970 00:00:00 +0000 +Message-Id: <example@example.com> +Received: from localhost (localhost [127.0.0.1]) by localhost + with SMTP id example for <example@example.com>; + Thu, 1 Jan 1970 00:00:00 +0000 (UTC) + (envelope-from example-return-0000-example=example.com@example.com) +Received: (qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000 + +EOF; + +$mode = ICONV_MIME_DECODE_CONTINUE_ON_ERROR; +$charset = 'UTF-8'; + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $str argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_mime_decode_headers() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_mime_decode_headers($headers, $input, $charset)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_mime_decode_headers() : usage variations *** + +-- Iteration 1 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 2 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 3 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 4 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 5 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 6 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 7 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 8 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 9 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 10 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 11 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 12 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 13 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 14 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 15 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 16 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, object given in %s on line %d +bool(false) + +-- Iteration 22 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 23 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 24 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_mime_decode_headers_variation3.phpt b/ext/iconv/tests/iconv_mime_decode_headers_variation3.phpt new file mode 100644 index 0000000..c4a9cc4 --- /dev/null +++ b/ext/iconv/tests/iconv_mime_decode_headers_variation3.phpt @@ -0,0 +1,482 @@ +--TEST-- +Test iconv_mime_encode() function : usage variations - Pass different data types to charset arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_mime_decode_headers') or die("skip iconv_mime_decode_headers() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : array iconv_mime_decode_headers(string headers [, int mode, string charset]) + * Description: Decodes multiple mime header fields + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass different data types to $str argument to see how iconv_mime_decode_headers() behaves + */ + +echo "*** Testing iconv_mime_decode_headers() : usage variations ***\n"; + +// Some of the parameters actually passed to charset will request to use +// a default charset determined by the platform. In order for this test to +// run on both linux and windows, the subject will have to be ascii only. +// Initialise function arguments not being substituted +$headers = <<<EOF +Subject: =?UTF-8?B?QSBTYW1wbGUgVGVzdA==?= +To: example@example.com +Date: Thu, 1 Jan 1970 00:00:00 +0000 +Message-Id: <example@example.com> +Received: from localhost (localhost [127.0.0.1]) by localhost + with SMTP id example for <example@example.com>; + Thu, 1 Jan 1970 00:00:00 +0000 (UTC) + (envelope-from example-return-0000-example=example.com@example.com) +Received: (qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000 + +EOF; + +$mode = ICONV_MIME_DECODE_CONTINUE_ON_ERROR; +$charset = 'UTF-8'; + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $str argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_mime_decode_headers() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_mime_decode_headers($headers, $input, $charset)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_mime_decode_headers() : usage variations *** + +-- Iteration 1 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 2 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 3 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 4 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 5 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 6 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 7 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 8 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 9 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 10 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 11 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 12 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 13 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 14 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 15 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 16 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, object given in %s on line %d +bool(false) + +-- Iteration 22 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 23 -- +array(5) { + ["Subject"]=> + string(13) "A Sample Test" + ["To"]=> + string(19) "example@example.com" + ["Date"]=> + string(30) "Thu, 1 Jan 1970 00:00:00 +0000" + ["Message-Id"]=> + string(21) "<example@example.com>" + ["Received"]=> + array(2) { + [0]=> + string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" + [1]=> + string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" + } +} + +-- Iteration 24 -- + +Warning: iconv_mime_decode_headers() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_mime_decode_variation1.phpt b/ext/iconv/tests/iconv_mime_decode_variation1.phpt new file mode 100644 index 0000000..a42b0de --- /dev/null +++ b/ext/iconv/tests/iconv_mime_decode_variation1.phpt @@ -0,0 +1,183 @@ +--TEST-- +Test iconv_mime_decode() function : usage variations - Pass different data types to header arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_mime_decode') or die("skip iconv_mime_decode() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : string iconv_mime_decode(string encoded_string [, int mode, string charset]) + * Description: Decodes a mime header field + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass different data types to $str argument to see how iconv_mime_decode() behaves + */ + +echo "*** Testing iconv_mime_decode() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$header = b'Subject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?='; +$mode = ICONV_MIME_DECODE_CONTINUE_ON_ERROR; +$charset = 'ISO-8859-1'; + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $str argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_mime_decode() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_mime_decode($input, $mode, $charset)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_mime_decode() : usage variations *** + +-- Iteration 1 -- +string(1) "0" + +-- Iteration 2 -- +string(1) "1" + +-- Iteration 3 -- +string(5) "12345" + +-- Iteration 4 -- +string(5) "-2345" + +-- Iteration 5 -- +string(4) "10.5" + +-- Iteration 6 -- +string(5) "-10.5" + +-- Iteration 7 -- +string(12) "123456789000" + +-- Iteration 8 -- +string(13) "1.23456789E-9" + +-- Iteration 9 -- +string(3) "0.5" + +-- Iteration 10 -- +string(0) "" + +-- Iteration 11 -- +string(0) "" + +-- Iteration 12 -- +string(1) "1" + +-- Iteration 13 -- +string(0) "" + +-- Iteration 14 -- +string(1) "1" + +-- Iteration 15 -- +string(0) "" + +-- Iteration 16 -- +string(0) "" + +-- Iteration 17 -- +string(0) "" + +-- Iteration 18 -- +string(6) "string" + +-- Iteration 19 -- +string(6) "string" + +-- Iteration 20 -- +string(11) "hello world" + +-- Iteration 21 -- +string(14) "Class A object" + +-- Iteration 22 -- +string(0) "" + +-- Iteration 23 -- +string(0) "" + +-- Iteration 24 -- + +Warning: iconv_mime_decode() expects parameter 1 to be string, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_mime_decode_variation2.phpt b/ext/iconv/tests/iconv_mime_decode_variation2.phpt new file mode 100644 index 0000000..1d82822 --- /dev/null +++ b/ext/iconv/tests/iconv_mime_decode_variation2.phpt @@ -0,0 +1,195 @@ +--TEST-- +Test iconv_mime_decode() function : usage variations - Pass different data types to mode arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_mime_decode') or die("skip iconv_mime_decode() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : string iconv_mime_decode(string encoded_string [, int mode, string charset]) + * Description: Decodes a mime header field + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass different data types to $str argument to see how iconv_mime_decode() behaves + */ + +echo "*** Testing iconv_mime_decode() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$header = b'Subject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?='; +$mode = ICONV_MIME_DECODE_CONTINUE_ON_ERROR; +$charset = 'UTF-8'; + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $str argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_mime_decode() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( bin2hex(iconv_mime_decode($header, $input, $charset))); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_mime_decode() : usage variations *** + +-- Iteration 1 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 2 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 3 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 4 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 5 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 6 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 7 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 8 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 9 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 10 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 11 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 12 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 13 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 14 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 15 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 16 -- + +Warning: iconv_mime_decode() expects parameter 2 to be long, string given in %s on line %d +string(0) "" + +-- Iteration 17 -- + +Warning: iconv_mime_decode() expects parameter 2 to be long, string given in %s on line %d +string(0) "" + +-- Iteration 18 -- + +Warning: iconv_mime_decode() expects parameter 2 to be long, string given in %s on line %d +string(0) "" + +-- Iteration 19 -- + +Warning: iconv_mime_decode() expects parameter 2 to be long, string given in %s on line %d +string(0) "" + +-- Iteration 20 -- + +Warning: iconv_mime_decode() expects parameter 2 to be long, string given in %s on line %d +string(0) "" + +-- Iteration 21 -- + +Warning: iconv_mime_decode() expects parameter 2 to be long, object given in %s on line %d +string(0) "" + +-- Iteration 22 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 23 -- +string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67" + +-- Iteration 24 -- + +Warning: iconv_mime_decode() expects parameter 2 to be long, resource given in %s on line %d +string(0) "" +Done diff --git a/ext/iconv/tests/iconv_mime_decode_variation3.phpt b/ext/iconv/tests/iconv_mime_decode_variation3.phpt new file mode 100644 index 0000000..cd5c719 --- /dev/null +++ b/ext/iconv/tests/iconv_mime_decode_variation3.phpt @@ -0,0 +1,222 @@ +--TEST-- +Test iconv_mime_decode() function : usage variations - Pass different data types to charset arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_mime_decode') or die("skip iconv_mime_decode() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : string iconv_mime_decode(string encoded_string [, int mode, string charset]) + * Description: Decodes a mime header field + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass different data types to $str argument to see how iconv_mime_decode() behaves + */ + +echo "*** Testing iconv_mime_decode() : usage variations ***\n"; + +// Initialise function arguments not being substituted +// Some of the parameters actually passed to charset will request to use +// a default charset determined by the platform. In order for this test to +// run on both linux and windows, the subject will have to be ascii only. +$header = b'Subject: =?UTF-8?B?QSBTYW1wbGUgVGVzdA==?='; +$mode = ICONV_MIME_DECODE_CONTINUE_ON_ERROR; +$charset = 'UTF-8'; + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $str argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_mime_decode() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + $res = iconv_mime_decode($header, $mode, $input); + if ($res !== false) { + var_dump(bin2hex($res)); + } + else { + var_dump($res); + } + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_mime_decode() : usage variations *** + +-- Iteration 1 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `0' is not allowed in %s on line %d +bool(false) + +-- Iteration 2 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `1' is not allowed in %s on line %d +bool(false) + +-- Iteration 3 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `12345' is not allowed in %s on line %d +bool(false) + +-- Iteration 4 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `-2345' is not allowed in %s on line %d +bool(false) + +-- Iteration 5 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `10.5' is not allowed in %s on line %d +bool(false) + +-- Iteration 6 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `-10.5' is not allowed in %s on line %d +bool(false) + +-- Iteration 7 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `123456789000' is not allowed in %s on line %d +bool(false) + +-- Iteration 8 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `1.23456789E-9' is not allowed in %s on line %d +bool(false) + +-- Iteration 9 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `0.5' is not allowed in %s on line %d +bool(false) + +-- Iteration 10 -- +string(44) "5375626a6563743a20412053616d706c652054657374" + +-- Iteration 11 -- +string(44) "5375626a6563743a20412053616d706c652054657374" + +-- Iteration 12 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `1' is not allowed in %s on line %d +bool(false) + +-- Iteration 13 -- +string(44) "5375626a6563743a20412053616d706c652054657374" + +-- Iteration 14 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `1' is not allowed in %s on line %d +bool(false) + +-- Iteration 15 -- +string(44) "5375626a6563743a20412053616d706c652054657374" + +-- Iteration 16 -- +string(44) "5375626a6563743a20412053616d706c652054657374" + +-- Iteration 17 -- +string(44) "5375626a6563743a20412053616d706c652054657374" + +-- Iteration 18 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `string' is not allowed in %s on line %d +bool(false) + +-- Iteration 19 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `string' is not allowed in %s on line %d +bool(false) + +-- Iteration 20 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `hello world' is not allowed in %s on line %d +bool(false) + +-- Iteration 21 -- + +Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `Class A object' is not allowed in %s on line %d +bool(false) + +-- Iteration 22 -- +string(44) "5375626a6563743a20412053616d706c652054657374" + +-- Iteration 23 -- +string(44) "5375626a6563743a20412053616d706c652054657374" + +-- Iteration 24 -- + +Warning: iconv_mime_decode() expects parameter 3 to be string, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_mime_encode.phpt b/ext/iconv/tests/iconv_mime_encode.phpt new file mode 100644 index 0000000..bd090e4 --- /dev/null +++ b/ext/iconv/tests/iconv_mime_encode.phpt @@ -0,0 +1,426 @@ +--TEST-- +iconv_mime_encode() +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--INI-- +iconv.internal_charset=iso-8859-1 +--FILE-- +<?php +function my_error_handler($errno, $errmsg, $filename, $linenum, $vars) +{ + echo "$errno: $errmsg\n"; +} +set_error_handler('my_error_handler'); +$preference = array( + "scheme" => "B", + "output-charset" => "ISO-2022-JP", + "input-charset" => "EUC-JP", + "line-break-chars" => "\n" +); +for ($line_len= 0; $line_len < 80; ++$line_len) { + print "-------- line length=$line_len\n"; + $preference["line-length"] = $line_len; + $result = iconv_mime_encode("From", "ץʸץʸܸƥ", $preference); + var_dump($result); + if ($result !== false) { + $max = max(array_map("strlen", explode("\n", $result))); + print "-------- "; + var_dump(($max <= $line_len)); + } else { + print "-------- \n"; + } +} +?> +--EXPECTF-- +-------- line length=0 +2: %s +bool(false) +-------- +-------- line length=1 +2: %s +bool(false) +-------- +-------- line length=2 +2: %s +bool(false) +-------- +-------- line length=3 +2: %s +bool(false) +-------- +-------- line length=4 +2: %s +bool(false) +-------- +-------- line length=5 +2: %s +bool(false) +-------- +-------- line length=6 +2: %s +bool(false) +-------- +-------- line length=7 +2: %s +bool(false) +-------- +-------- line length=8 +2: %s +bool(false) +-------- +-------- line length=9 +2: %s +bool(false) +-------- +-------- line length=10 +2: %s +bool(false) +-------- +-------- line length=11 +2: %s +bool(false) +-------- +-------- line length=12 +2: %s +bool(false) +-------- +-------- line length=13 +2: %s +bool(false) +-------- +-------- line length=14 +2: %s +bool(false) +-------- +-------- line length=15 +2: %s +bool(false) +-------- +-------- line length=16 +2: %s +bool(false) +-------- +-------- line length=17 +2: %s +bool(false) +-------- +-------- line length=18 +2: %s +bool(false) +-------- +-------- line length=19 +2: %s +bool(false) +-------- +-------- line length=20 +2: %s +bool(false) +-------- +-------- line length=21 +2: %s +bool(false) +-------- +-------- line length=22 +2: %s +bool(false) +-------- +-------- line length=23 +2: %s +bool(false) +-------- +-------- line length=24 +2: %s +bool(false) +-------- +-------- line length=25 +2: %s +bool(false) +-------- +-------- line length=26 +2: %s +bool(false) +-------- +-------- line length=27 +2: %s +bool(false) +-------- +-------- line length=28 +2: %s +bool(false) +-------- +-------- line length=29 +2: %s +bool(false) +-------- +-------- line length=30 +2: %s +bool(false) +-------- +-------- line length=31 +2: %s +bool(false) +-------- +-------- line length=32 +2: %s +bool(false) +-------- +-------- line length=33 +2: %s +bool(false) +-------- +-------- line length=34 +2: %s +bool(false) +-------- +-------- line length=35 +2: %s +bool(false) +-------- +-------- line length=36 +string(396) "From: =?ISO-2022-JP?B?GyRCJTUbKEI=?= + =?ISO-2022-JP?B?GyRCJXMlVxsoQg==?= + =?ISO-2022-JP?B?GyRCJWtKOBsoQg==?= + =?ISO-2022-JP?B?GyRCO3pOcxsoQg==?= + =?ISO-2022-JP?B?GyRCJTUlcxsoQg==?= + =?ISO-2022-JP?B?GyRCJVclaxsoQg==?= + =?ISO-2022-JP?B?GyRCSjg7ehsoQg==?= + =?ISO-2022-JP?B?GyRCTnNGfBsoQg==?= + =?ISO-2022-JP?B?GyRCS1w4bBsoQg==?= + =?ISO-2022-JP?B?GyRCJUYlLRsoQg==?= + =?ISO-2022-JP?B?GyRCJTklSBsoQg==?=" +-------- bool(true) +-------- line length=37 +string(396) "From: =?ISO-2022-JP?B?GyRCJTUbKEI=?= + =?ISO-2022-JP?B?GyRCJXMlVxsoQg==?= + =?ISO-2022-JP?B?GyRCJWtKOBsoQg==?= + =?ISO-2022-JP?B?GyRCO3pOcxsoQg==?= + =?ISO-2022-JP?B?GyRCJTUlcxsoQg==?= + =?ISO-2022-JP?B?GyRCJVclaxsoQg==?= + =?ISO-2022-JP?B?GyRCSjg7ehsoQg==?= + =?ISO-2022-JP?B?GyRCTnNGfBsoQg==?= + =?ISO-2022-JP?B?GyRCS1w4bBsoQg==?= + =?ISO-2022-JP?B?GyRCJUYlLRsoQg==?= + =?ISO-2022-JP?B?GyRCJTklSBsoQg==?=" +-------- bool(true) +-------- line length=38 +string(396) "From: =?ISO-2022-JP?B?GyRCJTUbKEI=?= + =?ISO-2022-JP?B?GyRCJXMlVxsoQg==?= + =?ISO-2022-JP?B?GyRCJWtKOBsoQg==?= + =?ISO-2022-JP?B?GyRCO3pOcxsoQg==?= + =?ISO-2022-JP?B?GyRCJTUlcxsoQg==?= + =?ISO-2022-JP?B?GyRCJVclaxsoQg==?= + =?ISO-2022-JP?B?GyRCSjg7ehsoQg==?= + =?ISO-2022-JP?B?GyRCTnNGfBsoQg==?= + =?ISO-2022-JP?B?GyRCS1w4bBsoQg==?= + =?ISO-2022-JP?B?GyRCJUYlLRsoQg==?= + =?ISO-2022-JP?B?GyRCJTklSBsoQg==?=" +-------- bool(true) +-------- line length=39 +string(236) "From: =?ISO-2022-JP?B?GyRCJTUbKEI=?= + =?ISO-2022-JP?B?GyRCJXMlVyVrSjgbKEI=?= + =?ISO-2022-JP?B?GyRCO3pOcyU1JXMbKEI=?= + =?ISO-2022-JP?B?GyRCJVcla0o4O3obKEI=?= + =?ISO-2022-JP?B?GyRCTnNGfEtcOGwbKEI=?= + =?ISO-2022-JP?B?GyRCJUYlLSU5JUgbKEI=?=" +-------- bool(true) +-------- line length=40 +string(236) "From: =?ISO-2022-JP?B?GyRCJTUlcxsoQg==?= + =?ISO-2022-JP?B?GyRCJVcla0o4O3obKEI=?= + =?ISO-2022-JP?B?GyRCTnMlNSVzJVcbKEI=?= + =?ISO-2022-JP?B?GyRCJWtKODt6TnMbKEI=?= + =?ISO-2022-JP?B?GyRCRnxLXDhsJUYbKEI=?= + =?ISO-2022-JP?B?GyRCJS0lOSVIGyhC?=" +-------- bool(true) +-------- line length=41 +string(236) "From: =?ISO-2022-JP?B?GyRCJTUlcxsoQg==?= + =?ISO-2022-JP?B?GyRCJVcla0o4O3obKEI=?= + =?ISO-2022-JP?B?GyRCTnMlNSVzJVcbKEI=?= + =?ISO-2022-JP?B?GyRCJWtKODt6TnMbKEI=?= + =?ISO-2022-JP?B?GyRCRnxLXDhsJUYbKEI=?= + =?ISO-2022-JP?B?GyRCJS0lOSVIGyhC?=" +-------- bool(true) +-------- line length=42 +string(236) "From: =?ISO-2022-JP?B?GyRCJTUlcxsoQg==?= + =?ISO-2022-JP?B?GyRCJVcla0o4O3obKEI=?= + =?ISO-2022-JP?B?GyRCTnMlNSVzJVcbKEI=?= + =?ISO-2022-JP?B?GyRCJWtKODt6TnMbKEI=?= + =?ISO-2022-JP?B?GyRCRnxLXDhsJUYbKEI=?= + =?ISO-2022-JP?B?GyRCJS0lOSVIGyhC?=" +-------- bool(true) +-------- line length=43 +string(212) "From: =?ISO-2022-JP?B?GyRCJTUlcxsoQg==?= + =?ISO-2022-JP?B?GyRCJVcla0o4O3pOcxsoQg==?= + =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKOBsoQg==?= + =?ISO-2022-JP?B?GyRCO3pOc0Z8S1w4bBsoQg==?= + =?ISO-2022-JP?B?GyRCJUYlLSU5JUgbKEI=?=" +-------- bool(true) +-------- line length=44 +string(212) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWsbKEI=?= + =?ISO-2022-JP?B?GyRCSjg7ek5zJTUlcxsoQg==?= + =?ISO-2022-JP?B?GyRCJVcla0o4O3pOcxsoQg==?= + =?ISO-2022-JP?B?GyRCRnxLXDhsJUYlLRsoQg==?= + =?ISO-2022-JP?B?GyRCJTklSBsoQg==?=" +-------- bool(true) +-------- line length=45 +string(212) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWsbKEI=?= + =?ISO-2022-JP?B?GyRCSjg7ek5zJTUlcxsoQg==?= + =?ISO-2022-JP?B?GyRCJVcla0o4O3pOcxsoQg==?= + =?ISO-2022-JP?B?GyRCRnxLXDhsJUYlLRsoQg==?= + =?ISO-2022-JP?B?GyRCJTklSBsoQg==?=" +-------- bool(true) +-------- line length=46 +string(212) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWsbKEI=?= + =?ISO-2022-JP?B?GyRCSjg7ek5zJTUlcxsoQg==?= + =?ISO-2022-JP?B?GyRCJVcla0o4O3pOcxsoQg==?= + =?ISO-2022-JP?B?GyRCRnxLXDhsJUYlLRsoQg==?= + =?ISO-2022-JP?B?GyRCJTklSBsoQg==?=" +-------- bool(true) +-------- line length=47 +string(176) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWsbKEI=?= + =?ISO-2022-JP?B?GyRCSjg7ek5zJTUlcyVXJWsbKEI=?= + =?ISO-2022-JP?B?GyRCSjg7ek5zRnxLXDhsJUYbKEI=?= + =?ISO-2022-JP?B?GyRCJS0lOSVIGyhC?=" +-------- bool(true) +-------- line length=48 +string(180) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKOBsoQg==?= + =?ISO-2022-JP?B?GyRCO3pOcyU1JXMlVyVrSjgbKEI=?= + =?ISO-2022-JP?B?GyRCO3pOc0Z8S1w4bCVGJS0bKEI=?= + =?ISO-2022-JP?B?GyRCJTklSBsoQg==?=" +-------- bool(true) +-------- line length=49 +string(180) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKOBsoQg==?= + =?ISO-2022-JP?B?GyRCO3pOcyU1JXMlVyVrSjgbKEI=?= + =?ISO-2022-JP?B?GyRCO3pOc0Z8S1w4bCVGJS0bKEI=?= + =?ISO-2022-JP?B?GyRCJTklSBsoQg==?=" +-------- bool(true) +-------- line length=50 +string(180) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKOBsoQg==?= + =?ISO-2022-JP?B?GyRCO3pOcyU1JXMlVyVrSjgbKEI=?= + =?ISO-2022-JP?B?GyRCO3pOc0Z8S1w4bCVGJS0bKEI=?= + =?ISO-2022-JP?B?GyRCJTklSBsoQg==?=" +-------- bool(true) +-------- line length=51 +string(152) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKOBsoQg==?= + =?ISO-2022-JP?B?GyRCO3pOcyU1JXMlVyVrSjg7ehsoQg==?= + =?ISO-2022-JP?B?GyRCTnNGfEtcOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) +-------- line length=52 +string(148) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMbKEI=?= + =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnNGfBsoQg==?= + =?ISO-2022-JP?B?GyRCS1w4bCVGJS0lOSVIGyhC?=" +-------- bool(true) +-------- line length=53 +string(148) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMbKEI=?= + =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnNGfBsoQg==?= + =?ISO-2022-JP?B?GyRCS1w4bCVGJS0lOSVIGyhC?=" +-------- bool(true) +-------- line length=54 +string(148) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMbKEI=?= + =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnNGfBsoQg==?= + =?ISO-2022-JP?B?GyRCS1w4bCVGJS0lOSVIGyhC?=" +-------- bool(true) +-------- line length=55 +string(148) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMbKEI=?= + =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnNGfEtcOGwbKEI=?= + =?ISO-2022-JP?B?GyRCJUYlLSU5JUgbKEI=?=" +-------- bool(true) +-------- line length=56 +string(148) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNRsoQg==?= + =?ISO-2022-JP?B?GyRCJXMlVyVrSjg7ek5zRnxLXDhsJUYbKEI=?= + =?ISO-2022-JP?B?GyRCJS0lOSVIGyhC?=" +-------- bool(true) +-------- line length=57 +string(148) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNRsoQg==?= + =?ISO-2022-JP?B?GyRCJXMlVyVrSjg7ek5zRnxLXDhsJUYbKEI=?= + =?ISO-2022-JP?B?GyRCJS0lOSVIGyhC?=" +-------- bool(true) +-------- line length=58 +string(148) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNRsoQg==?= + =?ISO-2022-JP?B?GyRCJXMlVyVrSjg7ek5zRnxLXDhsJUYbKEI=?= + =?ISO-2022-JP?B?GyRCJS0lOSVIGyhC?=" +-------- bool(true) +-------- line length=59 +string(152) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNRsoQg==?= + =?ISO-2022-JP?B?GyRCJXMlVyVrSjg7ek5zRnxLXDhsJUYlLRsoQg==?= + =?ISO-2022-JP?B?GyRCJTklSBsoQg==?=" +-------- bool(true) +-------- line length=60 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcbKEI=?= + =?ISO-2022-JP?B?GyRCJWtKODt6TnNGfEtcOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) +-------- line length=61 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcbKEI=?= + =?ISO-2022-JP?B?GyRCJWtKODt6TnNGfEtcOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) +-------- line length=62 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcbKEI=?= + =?ISO-2022-JP?B?GyRCJWtKODt6TnNGfEtcOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) +-------- line length=63 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcbKEI=?= + =?ISO-2022-JP?B?GyRCJWtKODt6TnNGfEtcOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) +-------- line length=64 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVclaxsoQg==?= + =?ISO-2022-JP?B?GyRCSjg7ek5zRnxLXDhsJUYlLSU5JUgbKEI=?=" +-------- bool(true) +-------- line length=65 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVclaxsoQg==?= + =?ISO-2022-JP?B?GyRCSjg7ek5zRnxLXDhsJUYlLSU5JUgbKEI=?=" +-------- bool(true) +-------- line length=66 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVclaxsoQg==?= + =?ISO-2022-JP?B?GyRCSjg7ek5zRnxLXDhsJUYlLSU5JUgbKEI=?=" +-------- bool(true) +-------- line length=67 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVclaxsoQg==?= + =?ISO-2022-JP?B?GyRCSjg7ek5zRnxLXDhsJUYlLSU5JUgbKEI=?=" +-------- bool(true) +-------- line length=68 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcla0o4O3obKEI=?= + =?ISO-2022-JP?B?GyRCTnNGfEtcOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) +-------- line length=69 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcla0o4O3obKEI=?= + =?ISO-2022-JP?B?GyRCTnNGfEtcOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) +-------- line length=70 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcla0o4O3obKEI=?= + =?ISO-2022-JP?B?GyRCTnNGfEtcOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) +-------- line length=71 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcla0o4O3obKEI=?= + =?ISO-2022-JP?B?GyRCTnNGfEtcOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) +-------- line length=72 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcla0o4O3pOcxsoQg==?= + =?ISO-2022-JP?B?GyRCRnxLXDhsJUYlLSU5JUgbKEI=?=" +-------- bool(true) +-------- line length=73 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcla0o4O3pOcxsoQg==?= + =?ISO-2022-JP?B?GyRCRnxLXDhsJUYlLSU5JUgbKEI=?=" +-------- bool(true) +-------- line length=74 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcla0o4O3pOcxsoQg==?= + =?ISO-2022-JP?B?GyRCRnxLXDhsJUYlLSU5JUgbKEI=?=" +-------- bool(true) +-------- line length=75 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcla0o4O3pOcxsoQg==?= + =?ISO-2022-JP?B?GyRCRnxLXDhsJUYlLSU5JUgbKEI=?=" +-------- bool(true) +-------- line length=76 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcla0o4O3pOc0Z8S1wbKEI=?= + =?ISO-2022-JP?B?GyRCOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) +-------- line length=77 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcla0o4O3pOc0Z8S1wbKEI=?= + =?ISO-2022-JP?B?GyRCOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) +-------- line length=78 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcla0o4O3pOc0Z8S1wbKEI=?= + =?ISO-2022-JP?B?GyRCOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) +-------- line length=79 +string(120) "From: =?ISO-2022-JP?B?GyRCJTUlcyVXJWtKODt6TnMlNSVzJVcla0o4O3pOc0Z8S1wbKEI=?= + =?ISO-2022-JP?B?GyRCOGwlRiUtJTklSBsoQg==?=" +-------- bool(true) diff --git a/ext/iconv/tests/iconv_set_encoding-charset-length-cve-2007-4840.phpt b/ext/iconv/tests/iconv_set_encoding-charset-length-cve-2007-4840.phpt new file mode 100644 index 0000000..e6abca5 --- /dev/null +++ b/ext/iconv/tests/iconv_set_encoding-charset-length-cve-2007-4840.phpt @@ -0,0 +1,21 @@ +--TEST-- +iconv_set_encoding() charset parameter length checks (CVE-2007-4840) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +$a = str_repeat("/", 9000000); +var_dump(iconv_set_encoding("input_encoding", $a)); +var_dump(iconv_set_encoding("output_encoding", $a)); +var_dump(iconv_set_encoding("internal_encoding", $a)); +?> +--EXPECTF-- + +Warning: iconv_set_encoding(): Charset parameter exceeds the maximum allowed length of %d characters in %s on line %d +bool(false) + +Warning: iconv_set_encoding(): Charset parameter exceeds the maximum allowed length of %d characters in %s on line %d +bool(false) + +Warning: iconv_set_encoding(): Charset parameter exceeds the maximum allowed length of %d characters in %s on line %d +bool(false) diff --git a/ext/iconv/tests/iconv_set_encoding_error.phpt b/ext/iconv/tests/iconv_set_encoding_error.phpt new file mode 100644 index 0000000..4ba8400 --- /dev/null +++ b/ext/iconv/tests/iconv_set_encoding_error.phpt @@ -0,0 +1,177 @@ +--TEST-- +Test iconv_set_encoding() function : basic functionality +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_set_encoding') or die("skip iconv_set_encoding() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : bool iconv_set_encoding(string type, string charset) + * Description: Sets internal encoding and output encoding for ob_iconv_handler() + * Source code: ext/iconv/iconv.c + */ + +/* + * Test Error functionality of iconv_get_encoding + */ + +echo "*** Testing iconv_set_encoding() : error functionality ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "UTF-8"; + } +} + +// heredoc string +$heredoc = <<<EOT +Nothing +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $encoding argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of mb_regex_encoding() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_set_encoding($input, "UTF-8") ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_set_encoding() : error functionality *** + +-- Iteration 1 -- +bool(false) + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- +bool(false) + +-- Iteration 20 -- +bool(false) + +-- Iteration 21 -- +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- + +Warning: iconv_set_encoding() expects parameter 1 to be string, resource given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_set_encoding_variation.phpt b/ext/iconv/tests/iconv_set_encoding_variation.phpt new file mode 100644 index 0000000..311a9f9 --- /dev/null +++ b/ext/iconv/tests/iconv_set_encoding_variation.phpt @@ -0,0 +1,307 @@ +--TEST-- +Test iconv_set_encoding() function : error functionality +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_set_encoding') or die("skip iconv_set_encoding() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : bool iconv_set_encoding(string type, string charset) + * Description: Sets internal encoding and output encoding for ob_iconv_handler() + * Source code: ext/iconv/iconv.c + */ + +/* + * Test Error functionality of iconv_get_encoding + */ + +echo "*** Testing iconv_set_encoding() : error functionality ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "UTF-8"; + } +} + +// heredoc string +$heredoc = <<<EOT +Nothing +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $encoding argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // invalid string data +/*18*/ "Nothing", + 'Nothing', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of mb_regex_encoding() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_set_encoding("internal_encoding", $input) ); + var_dump( iconv_set_encoding("input_encoding", $input) ); + var_dump( iconv_set_encoding("output_encoding", $input) ); + var_dump( iconv_get_encoding("internal_encoding") ); + var_dump( iconv_get_encoding("input_encoding") ); + var_dump( iconv_get_encoding("output_encoding") ); + + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_set_encoding() : error functionality *** + +-- Iteration 1 -- +bool(true) +bool(true) +bool(true) +string(1) "0" +string(1) "0" +string(1) "0" + +-- Iteration 2 -- +bool(true) +bool(true) +bool(true) +string(1) "1" +string(1) "1" +string(1) "1" + +-- Iteration 3 -- +bool(true) +bool(true) +bool(true) +string(5) "12345" +string(5) "12345" +string(5) "12345" + +-- Iteration 4 -- +bool(true) +bool(true) +bool(true) +string(5) "-2345" +string(5) "-2345" +string(5) "-2345" + +-- Iteration 5 -- +bool(true) +bool(true) +bool(true) +string(4) "10.5" +string(4) "10.5" +string(4) "10.5" + +-- Iteration 6 -- +bool(true) +bool(true) +bool(true) +string(5) "-10.5" +string(5) "-10.5" +string(5) "-10.5" + +-- Iteration 7 -- +bool(true) +bool(true) +bool(true) +string(12) "123456789000" +string(12) "123456789000" +string(12) "123456789000" + +-- Iteration 8 -- +bool(true) +bool(true) +bool(true) +string(13) "1.23456789E-9" +string(13) "1.23456789E-9" +string(13) "1.23456789E-9" + +-- Iteration 9 -- +bool(true) +bool(true) +bool(true) +string(3) "0.5" +string(3) "0.5" +string(3) "0.5" + +-- Iteration 10 -- +bool(true) +bool(true) +bool(true) +string(0) "" +string(0) "" +string(0) "" + +-- Iteration 11 -- +bool(true) +bool(true) +bool(true) +string(0) "" +string(0) "" +string(0) "" + +-- Iteration 12 -- +bool(true) +bool(true) +bool(true) +string(1) "1" +string(1) "1" +string(1) "1" + +-- Iteration 13 -- +bool(true) +bool(true) +bool(true) +string(0) "" +string(0) "" +string(0) "" + +-- Iteration 14 -- +bool(true) +bool(true) +bool(true) +string(1) "1" +string(1) "1" +string(1) "1" + +-- Iteration 15 -- +bool(true) +bool(true) +bool(true) +string(0) "" +string(0) "" +string(0) "" + +-- Iteration 16 -- +bool(true) +bool(true) +bool(true) +string(0) "" +string(0) "" +string(0) "" + +-- Iteration 17 -- +bool(true) +bool(true) +bool(true) +string(0) "" +string(0) "" +string(0) "" + +-- Iteration 18 -- +bool(true) +bool(true) +bool(true) +string(7) "Nothing" +string(7) "Nothing" +string(7) "Nothing" + +-- Iteration 19 -- +bool(true) +bool(true) +bool(true) +string(7) "Nothing" +string(7) "Nothing" +string(7) "Nothing" + +-- Iteration 20 -- +bool(true) +bool(true) +bool(true) +string(7) "Nothing" +string(7) "Nothing" +string(7) "Nothing" + +-- Iteration 21 -- +bool(true) +bool(true) +bool(true) +string(5) "UTF-8" +string(5) "UTF-8" +string(5) "UTF-8" + +-- Iteration 22 -- +bool(true) +bool(true) +bool(true) +string(0) "" +string(0) "" +string(0) "" + +-- Iteration 23 -- +bool(true) +bool(true) +bool(true) +string(0) "" +string(0) "" +string(0) "" + +-- Iteration 24 -- + +Warning: iconv_set_encoding() expects parameter 2 to be string, resource given in %s on line %d +NULL + +Warning: iconv_set_encoding() expects parameter 2 to be string, resource given in %s on line %d +NULL + +Warning: iconv_set_encoding() expects parameter 2 to be string, resource given in %s on line %d +NULL +string(0) "" +string(0) "" +string(0) "" +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_stream_filter.phpt b/ext/iconv/tests/iconv_stream_filter.phpt new file mode 100644 index 0000000..79f6ad5 --- /dev/null +++ b/ext/iconv/tests/iconv_stream_filter.phpt @@ -0,0 +1,39 @@ +--TEST-- +iconv stream filter +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--INI-- +iconv.internal_charset=iso-8859-1 +--FILE-- +<?php +$fp = fopen(dirname(__FILE__).'/iconv_stream_filter.txt', 'rb'); +var_dump(bin2hex(fread($fp, 10))); +var_dump(bin2hex(fread($fp, 5))); +var_dump(bin2hex(fread($fp, 1))); +fclose($fp); + +$fp = fopen(dirname(__FILE__).'/iconv_stream_filter.txt', 'rb'); +stream_filter_append($fp, 'convert.iconv.ISO-2022-JP/EUC-JP'); +var_dump(bin2hex(fread($fp, 10))); +var_dump(bin2hex(fread($fp, 5))); +var_dump(bin2hex(fread($fp, 1))); +fclose($fp); + +$fp = fopen(dirname(__FILE__).'/iconv_stream_filter.txt', 'rb'); +stream_filter_append($fp, 'string.rot13'); // this will make conversion fail. +stream_filter_append($fp, 'convert.iconv.ISO-2022-JP/EUC-JP'); +var_dump(bin2hex(@fread($fp, 10)) != "a4b3a4f3a4cba4c1a4cf"); +var_dump(bin2hex(fread($fp, 5)) != "69636f6e76"); +var_dump(bin2hex(fread($fp, 1)) != "0a"); +fclose($fp); +?> +--EXPECTF-- +string(20) "1b244224332473244b24" +string(10) "41244f1b28" +string(2) "42" +string(20) "a4b3a4f3a4cba4c1a4cf" +string(10) "69636f6e76" +string(2) "0a" +bool(true) +bool(true) +bool(true) diff --git a/ext/iconv/tests/iconv_stream_filter.txt b/ext/iconv/tests/iconv_stream_filter.txt new file mode 100644 index 0000000..1074d2a --- /dev/null +++ b/ext/iconv/tests/iconv_stream_filter.txt @@ -0,0 +1 @@ +$B$3$s$K$A$O(Biconv diff --git a/ext/iconv/tests/iconv_stream_filter_delimiter.phpt b/ext/iconv/tests/iconv_stream_filter_delimiter.phpt new file mode 100644 index 0000000..895f614 --- /dev/null +++ b/ext/iconv/tests/iconv_stream_filter_delimiter.phpt @@ -0,0 +1,50 @@ +--TEST-- +iconv stream filter +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--INI-- +iconv.internal_charset=iso-8859-1 +--FILE-- +<?php +$fp = fopen(dirname(__FILE__).'/iconv_stream_filter.txt', 'rb'); +var_dump(bin2hex(fread($fp, 10))); +var_dump(bin2hex(fread($fp, 5))); +var_dump(bin2hex(fread($fp, 1))); +fclose($fp); + +$fp = fopen(dirname(__FILE__).'/iconv_stream_filter.txt', 'rb'); +stream_filter_append($fp, 'convert.iconv.ISO-2022-JP/EUC-JP'); +var_dump(bin2hex(fread($fp, 10))); +var_dump(bin2hex(fread($fp, 5))); +var_dump(bin2hex(fread($fp, 1))); +fclose($fp); + +$fp = fopen(dirname(__FILE__).'/iconv_stream_filter.txt', 'rb'); +stream_filter_append($fp, 'convert.iconv.ISO-2022-JP.EUC-JP'); +var_dump(bin2hex(fread($fp, 10))); +var_dump(bin2hex(fread($fp, 5))); +var_dump(bin2hex(fread($fp, 1))); +fclose($fp); + +$fp = fopen(dirname(__FILE__).'/iconv_stream_filter.txt', 'rb'); +stream_filter_append($fp, 'convert.iconv.ISO-2022-JP\0EUC-JP'); +var_dump(bin2hex(fread($fp, 10))); +var_dump(bin2hex(fread($fp, 5))); +var_dump(bin2hex(fread($fp, 1))); +fclose($fp); +?> +--EXPECTF-- +string(20) "1b244224332473244b24" +string(10) "41244f1b28" +string(2) "42" +string(20) "a4b3a4f3a4cba4c1a4cf" +string(10) "69636f6e76" +string(2) "0a" +string(20) "a4b3a4f3a4cba4c1a4cf" +string(10) "69636f6e76" +string(2) "0a" + +Warning: stream_filter_append(): unable to create or locate filter "convert.iconv.ISO-2022-JP\0EUC-JP" in %siconv_stream_filter_delimiter.php on line %d +string(20) "1b244224332473244b24" +string(10) "41244f1b28" +string(2) "42" diff --git a/ext/iconv/tests/iconv_strlen-charset-length-cve-2007-4840.phpt b/ext/iconv/tests/iconv_strlen-charset-length-cve-2007-4840.phpt new file mode 100644 index 0000000..348cfb1 --- /dev/null +++ b/ext/iconv/tests/iconv_strlen-charset-length-cve-2007-4840.phpt @@ -0,0 +1,13 @@ +--TEST-- +iconv_strlen() charset parameter length checks (CVE-2007-4840) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +$a = str_repeat("/", 9791999); +var_dump(iconv_strlen(1, $a)); +?> +--EXPECTF-- + +Warning: iconv_strlen(): Charset parameter exceeds the maximum allowed length of %d characters in %s on line %d +bool(false) diff --git a/ext/iconv/tests/iconv_strlen.phpt b/ext/iconv/tests/iconv_strlen.phpt new file mode 100644 index 0000000..2c815f4 --- /dev/null +++ b/ext/iconv/tests/iconv_strlen.phpt @@ -0,0 +1,19 @@ +--TEST-- +iconv_strlen() +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +function foo($str, $charset) { + var_dump(strlen($str)); + var_dump(iconv_strlen($str, $charset)); +} + +foo("abc", "ASCII"); +foo("ܸ EUC-JP", "EUC-JP"); +?> +--EXPECT-- +int(3) +int(3) +int(13) +int(10) diff --git a/ext/iconv/tests/iconv_strlen_basic.phpt b/ext/iconv/tests/iconv_strlen_basic.phpt new file mode 100644 index 0000000..5777435 --- /dev/null +++ b/ext/iconv/tests/iconv_strlen_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test iconv_strlen() function : basic functionality +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strlen') or die("skip iconv_strlen() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strlen(string str [, string charset]) + * Description: Get character numbers of a string + * Source code: ext/iconv/iconv.c + */ + +/* + * Test basic functionality of iconv_strlen() + */ + +echo "*** Testing iconv_strlen() : basic functionality***\n"; + +$string_ascii = b'abc def'; +//Japanese string in UTF-8 +$string_mb = base64_decode(b'5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); + +echo "\n-- ASCII String --\n"; +var_dump(iconv_strlen($string_ascii)); + +echo "\n-- Multibyte String --\n"; +var_dump(iconv_strlen($string_mb, 'UTF-8')); +?> +===DONE=== +--EXPECTF-- +*** Testing iconv_strlen() : basic functionality*** + +-- ASCII String -- +int(7) + +-- Multibyte String -- +int(21) +===DONE=== diff --git a/ext/iconv/tests/iconv_strlen_error1.phpt b/ext/iconv/tests/iconv_strlen_error1.phpt new file mode 100644 index 0000000..3c63b20 --- /dev/null +++ b/ext/iconv/tests/iconv_strlen_error1.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test iconv_strlen() function : error conditions - pass incorrect number of args +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strlen') or die("skip iconv_strlen() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strlen(string str [, string charset]) + * Description: Get character numbers of a string + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass iconv_strlen an incorrect number of arguments to test behaviour + */ + +echo "*** Testing iconv_strlen() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing iconv_strlen() function with Zero arguments --\n"; +var_dump( iconv_strlen() ); + +//Test iconv_strlen with one more than the expected number of arguments +echo "\n-- Testing iconv_strlen() function with more than expected no. of arguments --\n"; +$str = 'string_val'; +$encoding = 'string_val'; +$extra_arg = 10; +var_dump( iconv_strlen($str, $encoding, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing iconv_strlen() : error conditions *** + +-- Testing iconv_strlen() function with Zero arguments -- + +Warning: iconv_strlen() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing iconv_strlen() function with more than expected no. of arguments -- + +Warning: iconv_strlen() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/iconv/tests/iconv_strlen_error2.phpt b/ext/iconv/tests/iconv_strlen_error2.phpt new file mode 100644 index 0000000..6c760b1 --- /dev/null +++ b/ext/iconv/tests/iconv_strlen_error2.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test iconv_strlen() function : error conditions - pass an unknown encoding +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strlen') or die("skip iconv_strlen() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strlen(string str [, string charset]) + * Description: Get character numbers of a string + * Source code: ext/iconv/iconv.c + */ + +/* + * Test iconv_strlen when passed an unknown encoding + */ + +echo "*** Testing iconv_strlen() : error ***\n"; + +$string = 'abcdef'; + +$encoding = 'unknown-encoding'; + +var_dump(iconv_strlen($string, $encoding)); + +?> +===DONE=== +--EXPECTF-- +*** Testing iconv_strlen() : error *** + +Notice: iconv_strlen(): Wrong charset, conversion from `unknown-encoding' to `UCS-4LE' is not allowed in %s on line %d +bool(false) +===DONE=== diff --git a/ext/iconv/tests/iconv_strlen_variation1.phpt b/ext/iconv/tests/iconv_strlen_variation1.phpt new file mode 100644 index 0000000..e3e25aa --- /dev/null +++ b/ext/iconv/tests/iconv_strlen_variation1.phpt @@ -0,0 +1,193 @@ +--TEST-- +Test iconv_strlen() function : usage variations - Pass different data types as $str arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strlen') or die("skip iconv_strlen() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strlen(string str [, string charset]) + * Description: Get character numbers of a string + * Source code: ext/iconv/iconv.c + */ + +/* + * Test iconv_strlen by passing different data types as $str argument + */ + +echo "*** Testing iconv_strlen() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$encoding = 'utf-8'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $str argument +$inputs = array( + + // int data +/*1*/ + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data +/*5*/ + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float 12.3456789000e-10' => 12.3456789000e-10, + 'float .5' => .5, + + // null data +/*10*/ + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data +/*12*/ + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data +/*16*/ + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data +/*18*/ + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data +/*21*/ + 'instance of class' => new classA(), + + // undefined data +/*22*/ + 'undefined var' => @$undefined_var, + + // unset data +/*23*/ + 'unset var' => @$unset_var, + + // resource variable +/*24*/ + 'resource' => $fp +); + +// loop through each element of $inputs to check the behavior of iconv_strlen() +$iterator = 1; +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( iconv_strlen($value, $encoding)); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing iconv_strlen() : usage variations *** + +--int 0-- +int(1) + +--int 1-- +int(1) + +--int 12345-- +int(5) + +--int -12345-- +int(6) + +--float 10.5-- +int(4) + +--float -10.5-- +int(5) + +--float 12.3456789000e10-- +int(12) + +--float 12.3456789000e-10-- +int(13) + +--float .5-- +int(3) + +--uppercase NULL-- +int(0) + +--lowercase null-- +int(0) + +--lowercase true-- +int(1) + +--lowercase false-- +int(0) + +--uppercase TRUE-- +int(1) + +--uppercase FALSE-- +int(0) + +--empty string DQ-- +int(0) + +--empty string SQ-- +int(0) + +--string DQ-- +int(6) + +--string SQ-- +int(6) + +--mixed case string-- +int(6) + +--heredoc-- +int(11) + +--instance of class-- +int(14) + +--undefined var-- +int(0) + +--unset var-- +int(0) + +--resource-- + +Warning: iconv_strlen() expects parameter 1 to be string, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/iconv/tests/iconv_strlen_variation2.phpt b/ext/iconv/tests/iconv_strlen_variation2.phpt new file mode 100644 index 0000000..85dd048 --- /dev/null +++ b/ext/iconv/tests/iconv_strlen_variation2.phpt @@ -0,0 +1,204 @@ +--TEST-- +Test iconv_strlen() function : usage variations - Pass different data types as $encoding arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strlen') or die("skip iconv_strlen() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strlen(string str [, string charset]) + * Description: Get character numbers of a string + * Source code: ext/iconv/iconv.c + */ + +/* + * Test iconv_strlen() by passing different data types as $encoding argument. + * Where possible 'UTF-8' has been entered as a string value + */ + +echo "*** Testing iconv_strlen() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$str = 'string value'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "UTF-8"; + } +} + +// heredoc string +$heredoc = <<<EOT +UTF-8 +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "UTF-8", + 'UTF-8', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_strlen() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_strlen($str, $input)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing iconv_strlen() : usage variations *** + +-- Iteration 1 -- + +Notice: iconv_strlen(): Wrong charset, conversion from `0' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 2 -- + +Notice: iconv_strlen(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 3 -- + +Notice: iconv_strlen(): Wrong charset, conversion from `12345' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 4 -- + +Notice: iconv_strlen(): Wrong charset, conversion from `-2345' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 5 -- + +Notice: iconv_strlen(): Wrong charset, conversion from `10.5' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 6 -- + +Notice: iconv_strlen(): Wrong charset, conversion from `-10.5' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 7 -- + +Notice: iconv_strlen(): Wrong charset, conversion from `123456789000' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 8 -- + +Notice: iconv_strlen(): Wrong charset, conversion from `1.23456789E-9' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 9 -- + +Notice: iconv_strlen(): Wrong charset, conversion from `0.5' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 10 -- +int(12) + +-- Iteration 11 -- +int(12) + +-- Iteration 12 -- + +Notice: iconv_strlen(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 13 -- +int(12) + +-- Iteration 14 -- + +Notice: iconv_strlen(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 15 -- +int(12) + +-- Iteration 16 -- +int(12) + +-- Iteration 17 -- +int(12) + +-- Iteration 18 -- +int(12) + +-- Iteration 19 -- +int(12) + +-- Iteration 20 -- +int(12) + +-- Iteration 21 -- +int(12) + +-- Iteration 22 -- +int(12) + +-- Iteration 23 -- +int(12) + +-- Iteration 24 -- + +Warning: iconv_strlen() expects parameter 2 to be string, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_strpos-charset-length-cve-2007-4840.phpt b/ext/iconv/tests/iconv_strpos-charset-length-cve-2007-4840.phpt new file mode 100644 index 0000000..4cb858f --- /dev/null +++ b/ext/iconv/tests/iconv_strpos-charset-length-cve-2007-4840.phpt @@ -0,0 +1,13 @@ +--TEST-- +iconv_strpos() charset parameter length checks (CVE-2007-4840) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +$a = str_repeat("/", 9000000); +var_dump(iconv_strpos("a", "b", 0, $a)); +?> +--EXPECTF-- + +Warning: iconv_strpos(): Charset parameter exceeds the maximum allowed length of %d characters in %s on line %d +bool(false) diff --git a/ext/iconv/tests/iconv_strpos.phpt b/ext/iconv/tests/iconv_strpos.phpt new file mode 100644 index 0000000..6965f6f --- /dev/null +++ b/ext/iconv/tests/iconv_strpos.phpt @@ -0,0 +1,58 @@ +--TEST-- +iconv_strpos() +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--INI-- +iconv.internal_charset=ISO-8859-1 +--FILE-- +<?php +function my_error_handler($errno, $errmsg, $filename, $linenum, $vars) +{ + echo "$errno: $errmsg\n"; +} +set_error_handler('my_error_handler'); +function foo($haystk, $needle, $offset, $to_charset = false, $from_charset = false) +{ + if ($from_charset !== false) { + $haystk = iconv($from_charset, $to_charset, $haystk); + } + var_dump(strpos($haystk, $needle, $offset)); + if ($to_charset !== false) { + var_dump(iconv_strpos($haystk, $needle, $offset, $to_charset)); + } else { + var_dump(iconv_strpos($haystk, $needle, $offset)); + } +} +foo("abecdbcdabef", "bcd", -1); +foo("abecdbcdabef", "bcd", 100000); +foo("abcabcabcdabcababcdabc", "bcd", 0); +foo("abcabcabcdabcababcdabc", "bcd", 10); +foo(str_repeat("abcab", 60)."abcdb".str_repeat("adabc", 60), "abcd", 0); +foo(str_repeat("", 30)."".str_repeat("", 30), "", 0, "EUC-JP"); +$str = str_repeat("", 60).'$'.str_repeat("", 60); +foo($str, '$', 0, "ISO-2022-JP", "EUC-JP"); + +var_dump(iconv_strpos("string", "")); +var_dump(iconv_strpos("", "string")); + +?> +--EXPECTF-- +2: %s +bool(false) +2: %s +bool(false) +2: %s +bool(false) +bool(false) +int(7) +int(7) +int(16) +int(16) +int(300) +int(300) +int(302) +int(151) +int(1) +int(300) +bool(false) +bool(false) diff --git a/ext/iconv/tests/iconv_strpos_basic.phpt b/ext/iconv/tests/iconv_strpos_basic.phpt new file mode 100644 index 0000000..1604465 --- /dev/null +++ b/ext/iconv/tests/iconv_strpos_basic.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test iconv_strpos() function : basic functionality +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strpos') or die("skip iconv_strpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strpos(string haystack, string needle [, int offset [, string charset]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Test basic functionality of iconv_strpos with ASCII and multibyte characters + */ + +echo "*** Testing iconv_strpos() : basic functionality***\n"; + +iconv_set_encoding("internal_encoding", "UTF-8"); + +$string_ascii = b'abc def'; +//Japanese string in UTF-8 +$string_mb = base64_decode(b'5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); + +echo "\n-- ASCII string 1 --\n"; +var_dump(iconv_strpos($string_ascii, b'd', 2, 'ISO-8859-1')); + +echo "\n-- ASCII string 2 --\n"; +var_dump(iconv_strpos($string_ascii, b'123')); + +echo "\n-- Multibyte string 1 --\n"; +$needle1 = base64_decode('5pel5pys6Kqe'); +var_dump(iconv_strpos($string_mb, $needle1)); + +echo "\n-- Multibyte string 2 --\n"; +$needle2 = base64_decode(b"44GT44KT44Gr44Gh44Gv44CB5LiW55WM"); +var_dump(iconv_strpos($string_mb, $needle2)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_strpos() : basic functionality*** + +-- ASCII string 1 -- +int(4) + +-- ASCII string 2 -- +bool(false) + +-- Multibyte string 1 -- +int(0) + +-- Multibyte string 2 -- +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_strpos_error1.phpt b/ext/iconv/tests/iconv_strpos_error1.phpt new file mode 100644 index 0000000..2324665 --- /dev/null +++ b/ext/iconv/tests/iconv_strpos_error1.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test iconv_strpos() function : error conditions - Pass incorrect number of args +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strpos') or die("skip iconv_strpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strpos(string haystack, string needle [, int offset [, string charset]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Test how iconv_strpos behaves when passed an incorrect number of arguments + */ + +echo "*** Testing iconv_strpos() : error conditions ***\n"; + + +//Test iconv_strpos with one more than the expected number of arguments +echo "\n-- Testing iconv_strpos() function with more than expected no. of arguments --\n"; +$haystack = 'string_val'; +$needle = 'string_val'; +$offset = 10; +$encoding = 'string_val'; +$extra_arg = 10; +var_dump( iconv_strpos($haystack, $needle, $offset, $encoding, $extra_arg) ); + +// Testing iconv_strpos with one less than the expected number of arguments +echo "\n-- Testing iconv_strpos() function with less than expected no. of arguments --\n"; +$haystack = 'string_val'; +var_dump( iconv_strpos($haystack) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_strpos() : error conditions *** + +-- Testing iconv_strpos() function with more than expected no. of arguments -- + +Warning: iconv_strpos() expects at most 4 parameters, 5 given in %s on line %d +bool(false) + +-- Testing iconv_strpos() function with less than expected no. of arguments -- + +Warning: iconv_strpos() expects at least 2 parameters, 1 given in %s on line %d +bool(false) +Done diff --git a/ext/iconv/tests/iconv_strpos_error2.phpt b/ext/iconv/tests/iconv_strpos_error2.phpt new file mode 100644 index 0000000..01e728a --- /dev/null +++ b/ext/iconv/tests/iconv_strpos_error2.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test iconv_strpos() function : error conditions - Pass unknown encoding +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strpos') or die("skip iconv_strpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strpos(string haystack, string needle [, int offset [, string charset]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass an unknown encoding to iconv_strpos() to test behaviour + */ + +echo "*** Testing iconv_strpos() : error conditions ***\n"; +$haystack = 'Hello, world'; +$needle = 'world'; +$offset = 2; +$encoding = 'unknown-encoding'; + +var_dump( iconv_strpos($haystack, $needle, $offset, $encoding) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_strpos() : error conditions *** + +Notice: iconv_strpos(): Wrong charset, conversion from `unknown-encoding' to `UCS-4LE' is not allowed in %s on line %d +bool(false) +Done diff --git a/ext/iconv/tests/iconv_strpos_variation1.phpt b/ext/iconv/tests/iconv_strpos_variation1.phpt new file mode 100644 index 0000000..38dc353 --- /dev/null +++ b/ext/iconv/tests/iconv_strpos_variation1.phpt @@ -0,0 +1,182 @@ +--TEST-- +Test iconv_strpos() function : usage variations - pass different data types to $haystack arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strpos') or die("skip iconv_strpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strpos(string haystack, string needle [, int offset [, string charset]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass iconv_strpos different data types as $haystack arg to test behaviour + */ + +echo "*** Testing iconv_strpos() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$needle = 'string_val'; +$offset = 0; +$encoding = 'utf-8'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $haystack argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_strpos() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_strpos($input, $needle, $offset, $encoding)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_strpos() : usage variations *** + +-- Iteration 1 -- +bool(false) + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- +bool(false) + +-- Iteration 20 -- +bool(false) + +-- Iteration 21 -- +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- + +Warning: iconv_strpos() expects parameter 1 to be string, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_strpos_variation2.phpt b/ext/iconv/tests/iconv_strpos_variation2.phpt new file mode 100644 index 0000000..e702ca9 --- /dev/null +++ b/ext/iconv/tests/iconv_strpos_variation2.phpt @@ -0,0 +1,182 @@ +--TEST-- +Test iconv_strpos() function : usage variations - pass different data types as $needle arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strpos') or die("skip iconv_strpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strpos(string haystack, string needle [, int offset [, string charset]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass iconv_strpos different data types as $needle arg to test behaviour + */ + +echo "*** Testing iconv_strpos() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$haystack = 'string_val'; +$offset = 0; +$encoding = 'utf-8'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $needle argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_strpos() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_strpos($haystack, $input, $offset, $encoding)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_strpos() : usage variations *** + +-- Iteration 1 -- +bool(false) + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- +int(0) + +-- Iteration 19 -- +int(0) + +-- Iteration 20 -- +bool(false) + +-- Iteration 21 -- +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- + +Warning: iconv_strpos() expects parameter 2 to be string, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_strpos_variation3.phpt b/ext/iconv/tests/iconv_strpos_variation3.phpt new file mode 100644 index 0000000..3c333bf --- /dev/null +++ b/ext/iconv/tests/iconv_strpos_variation3.phpt @@ -0,0 +1,201 @@ +--TEST-- +Test iconv_strpos() function : usage variations - pass different data types as $offset arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strpos') or die("skip iconv_strpos() is not available in this build"); +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strpos(string haystack, string needle [, int offset [, string charset]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass iconv_strpos different data types as $offset arg to test behaviour + */ + +echo "*** Testing iconv_strpos() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$needle = b'a'; +$haystack = b'string_val'; +$encoding = 'utf-8'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $offest argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_strpos() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_strpos($haystack, $needle, $input, $encoding)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_strpos() : usage variations *** + +-- Iteration 1 -- +int(8) + +-- Iteration 2 -- +int(8) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- + +Warning: iconv_strpos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- + +Warning: iconv_strpos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: iconv_strpos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 8 -- +int(8) + +-- Iteration 9 -- +int(8) + +-- Iteration 10 -- +int(8) + +-- Iteration 11 -- +int(8) + +-- Iteration 12 -- +int(8) + +-- Iteration 13 -- +int(8) + +-- Iteration 14 -- +int(8) + +-- Iteration 15 -- +int(8) + +-- Iteration 16 -- + +Warning: iconv_strpos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: iconv_strpos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: iconv_strpos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: iconv_strpos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: iconv_strpos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: iconv_strpos() expects parameter 3 to be long, object given in %s on line %d +bool(false) + +-- Iteration 22 -- +int(8) + +-- Iteration 23 -- +int(8) + +-- Iteration 24 -- + +Warning: iconv_strpos() expects parameter 3 to be long, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_strpos_variation3_64bit.phpt b/ext/iconv/tests/iconv_strpos_variation3_64bit.phpt new file mode 100644 index 0000000..1cc8a84 --- /dev/null +++ b/ext/iconv/tests/iconv_strpos_variation3_64bit.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test iconv_strpos() function : usage variations - pass different data types as $offset arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strpos') or die("skip iconv_strpos() is not available in this build"); +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strpos(string haystack, string needle [, int offset [, string charset]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass iconv_strpos different data types as $offset arg to test behaviour + */ + +echo "*** Testing iconv_strpos() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$needle = b'a'; +$haystack = b'string_val'; +$encoding = 'utf-8'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $offest argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_strpos() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_strpos($haystack, $needle, $input, $encoding)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_strpos() : usage variations *** + +-- Iteration 1 -- +int(8) + +-- Iteration 2 -- +int(8) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- + +Warning: iconv_strpos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- + +Warning: iconv_strpos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 7 -- +int(8) + +-- Iteration 8 -- +int(8) + +-- Iteration 9 -- +int(8) + +-- Iteration 10 -- +int(8) + +-- Iteration 11 -- +int(8) + +-- Iteration 12 -- +int(8) + +-- Iteration 13 -- +int(8) + +-- Iteration 14 -- +int(8) + +-- Iteration 15 -- +int(8) + +-- Iteration 16 -- + +Warning: iconv_strpos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: iconv_strpos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: iconv_strpos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: iconv_strpos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: iconv_strpos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: iconv_strpos() expects parameter 3 to be long, object given in %s on line %d +bool(false) + +-- Iteration 22 -- +int(8) + +-- Iteration 23 -- +int(8) + +-- Iteration 24 -- + +Warning: iconv_strpos() expects parameter 3 to be long, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_strpos_variation4.phpt b/ext/iconv/tests/iconv_strpos_variation4.phpt new file mode 100644 index 0000000..43ab3e5 --- /dev/null +++ b/ext/iconv/tests/iconv_strpos_variation4.phpt @@ -0,0 +1,207 @@ +--TEST-- +Test iconv_strpos() function : usage variations - pass different data types as $charset arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strpos') or die("skip iconv_strpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strpos(string haystack, string needle [, int offset [, string charset]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + + +/* + * Pass iconv_strpos different data types as $encoding arg to test behaviour + * Where possible 'UTF-8' has been entered as a string value + */ + +echo "*** Testing iconv_strpos() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$haystack = b'string_val'; +$needle = b'val'; +$offset = 0; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "UTF-8"; + } +} + +// heredoc string +$heredoc = <<<EOT +UTF-8 +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "UTF-8", + 'UTF-8', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_strpos() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_strpos($haystack, $needle, $offset, $input)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing iconv_strpos() : usage variations *** + +-- Iteration 1 -- + +Notice: iconv_strpos(): Wrong charset, conversion from `0' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 2 -- + +Notice: iconv_strpos(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 3 -- + +Notice: iconv_strpos(): Wrong charset, conversion from `12345' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 4 -- + +Notice: iconv_strpos(): Wrong charset, conversion from `-2345' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 5 -- + +Notice: iconv_strpos(): Wrong charset, conversion from `10.5' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 6 -- + +Notice: iconv_strpos(): Wrong charset, conversion from `-10.5' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 7 -- + +Notice: iconv_strpos(): Wrong charset, conversion from `123456789000' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 8 -- + +Notice: iconv_strpos(): Wrong charset, conversion from `1.23456789E-9' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 9 -- + +Notice: iconv_strpos(): Wrong charset, conversion from `0.5' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 10 -- +int(7) + +-- Iteration 11 -- +int(7) + +-- Iteration 12 -- + +Notice: iconv_strpos(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 13 -- +int(7) + +-- Iteration 14 -- + +Notice: iconv_strpos(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 15 -- +int(7) + +-- Iteration 16 -- +int(7) + +-- Iteration 17 -- +int(7) + +-- Iteration 18 -- +int(7) + +-- Iteration 19 -- +int(7) + +-- Iteration 20 -- +int(7) + +-- Iteration 21 -- +int(7) + +-- Iteration 22 -- +int(7) + +-- Iteration 23 -- +int(7) + +-- Iteration 24 -- + +Warning: iconv_strpos() expects parameter 4 to be string, resource given in %s on line %d +bool(false) +Done diff --git a/ext/iconv/tests/iconv_strpos_variation5.phpt b/ext/iconv/tests/iconv_strpos_variation5.phpt new file mode 100644 index 0000000..57a7a90 --- /dev/null +++ b/ext/iconv/tests/iconv_strpos_variation5.phpt @@ -0,0 +1,101 @@ +--TEST-- +Test iconv_strpos() function : usage variations - Pass different integers as $offset argument +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strpos') or die("skip iconv_strpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int iconv_strpos(string haystack, string needle [, int offset [, string charset]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Test how iconv_strpos() behaves when passed different integers as $offset argument + * The character length of $string_ascii and $string_mb is the same, + * and the needle appears at the same positions in both strings + */ + +iconv_set_encoding("internal_encoding", "UTF-8"); + +echo "*** Testing iconv_strpos() : usage variations ***\n"; + +$string_ascii = b'+Is an English string'; //21 chars +$needle_ascii = b'g'; + +$string_mb = base64_decode(b'5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars +$needle_mb = base64_decode(b'44CC'); + +/* + * Loop through integers as multiples of ten for $offset argument + * iconv_strpos should not be able to accept negative values as $offset. + * 60 is larger than *BYTE* count for $string_mb + */ +for ($i = -10; $i <= 60; $i += 10) { + echo "\n**-- Offset is: $i --**\n"; + echo "-- ASCII String --\n"; + var_dump(iconv_strpos($string_ascii, $needle_ascii, $i)); + echo "--Multibyte String --\n"; + var_dump(iconv_strpos($string_mb, $needle_mb, $i, 'UTF-8')); +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing iconv_strpos() : usage variations *** + +**-- Offset is: -10 --** +-- ASCII String -- + +Warning: iconv_strpos(): Offset not contained in string. in %s on line %d +bool(false) +--Multibyte String -- + +Warning: iconv_strpos(): Offset not contained in string. in %s on line %d +bool(false) + +**-- Offset is: 0 --** +-- ASCII String -- +int(9) +--Multibyte String -- +int(9) + +**-- Offset is: 10 --** +-- ASCII String -- +int(20) +--Multibyte String -- +int(20) + +**-- Offset is: 20 --** +-- ASCII String -- +int(20) +--Multibyte String -- +int(20) + +**-- Offset is: 30 --** +-- ASCII String -- +bool(false) +--Multibyte String -- +bool(false) + +**-- Offset is: 40 --** +-- ASCII String -- +bool(false) +--Multibyte String -- +bool(false) + +**-- Offset is: 50 --** +-- ASCII String -- +bool(false) +--Multibyte String -- +bool(false) + +**-- Offset is: 60 --** +-- ASCII String -- +bool(false) +--Multibyte String -- +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_strrpos-charset-length-cve-2007-4840.phpt b/ext/iconv/tests/iconv_strrpos-charset-length-cve-2007-4840.phpt new file mode 100644 index 0000000..948cc67 --- /dev/null +++ b/ext/iconv/tests/iconv_strrpos-charset-length-cve-2007-4840.phpt @@ -0,0 +1,13 @@ +--TEST-- +iconv_strrpos() charset parameter length checks (CVE-2007-4840) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +$a = str_repeat("/", 9000000); +var_dump(iconv_strrpos("a", "b", $a)); +?> +--EXPECTF-- + +Warning: iconv_strrpos(): Charset parameter exceeds the maximum allowed length of %d characters in %s on line %d +bool(false) diff --git a/ext/iconv/tests/iconv_strrpos.phpt b/ext/iconv/tests/iconv_strrpos.phpt new file mode 100644 index 0000000..ee977f2 --- /dev/null +++ b/ext/iconv/tests/iconv_strrpos.phpt @@ -0,0 +1,62 @@ +--TEST-- +iconv_strrpos() +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--INI-- +iconv.internal_charset=ISO-8859-1 +--FILE-- +<?php +function my_error_handler($errno, $errmsg, $filename, $linenum, $vars) +{ + echo "$errno: $errmsg\n"; +} +set_error_handler('my_error_handler'); +function foo($haystk, $needle, $to_charset = false, $from_charset = false) +{ + if ($from_charset !== false) { + $haystk = iconv($from_charset, $to_charset, $haystk); + } + if ($to_charset !== false) { + var_dump(iconv_strlen($haystk, $to_charset)); + var_dump(iconv_strrpos($haystk, $needle, $to_charset)); + } else { + var_dump(iconv_strlen($haystk)); + var_dump(iconv_strrpos($haystk, $needle)); + } +} +foo("abecdbcdabcdef", "bcd"); +foo(str_repeat("abcab", 60)."abcdb".str_repeat("adabc", 60), "abcd"); +foo(str_repeat("", 30)."".str_repeat("", 30), "", "EUC-JP"); + +for ($i = 0; $i <=6; ++$i) { + $str = str_repeat("", 60).str_repeat('$', $i).str_repeat("", 60); + foo($str, '$', "ISO-2022-JP", "EUC-JP"); +} + +var_dump(iconv_strrpos("string", "")); +var_dump(iconv_strrpos("", "string")); + +?> +--EXPECT-- +int(14) +int(9) +int(605) +int(300) +int(305) +int(151) +int(600) +bool(false) +int(601) +int(300) +int(602) +int(301) +int(603) +int(302) +int(604) +int(303) +int(605) +int(304) +int(606) +int(305) +bool(false) +bool(false) diff --git a/ext/iconv/tests/iconv_strrpos_basic.phpt b/ext/iconv/tests/iconv_strrpos_basic.phpt new file mode 100644 index 0000000..e275681 --- /dev/null +++ b/ext/iconv/tests/iconv_strrpos_basic.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test iconv_strrpos() function : basic functionality +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strrpos') or die("skip iconv_strrpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : proto int iconv_strrpos(string haystack, string needle [, string charset]) + * Description: Find position of last occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Test basic functionality of iconv_strrpos() + */ + +echo "*** Testing iconv_strrpos() : basic ***\n"; + +iconv_set_encoding("internal_encoding", "UTF-8"); + +$string_ascii = b'This is an English string. 0123456789.'; +//Japanese string in UTF-8 +$string_mb = base64_decode(b'5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); + +echo "\n-- ASCII string 1 --\n"; +var_dump(iconv_strrpos($string_ascii, b'is', 'ISO-8859-1')); + +echo "\n-- ASCII string 2 --\n"; +var_dump(iconv_strrpos($string_ascii, b'hello, world')); + +echo "\n-- Multibyte string 1 --\n"; +$needle1 = base64_decode(b'44CC'); +var_dump(iconv_strrpos($string_mb, $needle1)); + +echo "\n-- Multibyte string 2 --\n"; +$needle2 = base64_decode(b'44GT44KT44Gr44Gh44Gv44CB5LiW55WM'); +var_dump(iconv_strrpos($string_mb, $needle2)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_strrpos() : basic *** + +-- ASCII string 1 -- +int(15) + +-- ASCII string 2 -- +bool(false) + +-- Multibyte string 1 -- +int(20) + +-- Multibyte string 2 -- +bool(false) +Done + diff --git a/ext/iconv/tests/iconv_strrpos_error1.phpt b/ext/iconv/tests/iconv_strrpos_error1.phpt new file mode 100644 index 0000000..9d185c7 --- /dev/null +++ b/ext/iconv/tests/iconv_strrpos_error1.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test iconv_strrpos() function : error conditions - pass incorrect number of args +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strrpos') or die("skip iconv_strrpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : proto int iconv_strrpos(string haystack, string needle [, string charset]) + * Description: Find position of last occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass iconv_strrpos() an incorrect number of arguments + */ + +echo "*** Testing iconv_strrpos() : error conditions ***\n"; + + +//Test iconv_strrpos with one more than the expected number of arguments +echo "\n-- Testing iconv_strrpos() function with more than expected no. of arguments --\n"; +$haystack = 'string_val'; +$needle = 'string_val'; +$encoding = 'string_val'; +$extra_arg = 10; +var_dump( iconv_strrpos($haystack, $needle, $encoding, $extra_arg) ); + +// Testing iconv_strrpos with one less than the expected number of arguments +echo "\n-- Testing iconv_strrpos() function with less than expected no. of arguments --\n"; +$haystack = 'string_val'; +var_dump( iconv_strrpos($haystack) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_strrpos() : error conditions *** + +-- Testing iconv_strrpos() function with more than expected no. of arguments -- + +Warning: iconv_strrpos() expects at most 3 parameters, 4 given in %s on line %d +bool(false) + +-- Testing iconv_strrpos() function with less than expected no. of arguments -- + +Warning: iconv_strrpos() expects at least 2 parameters, 1 given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_strrpos_error2.phpt b/ext/iconv/tests/iconv_strrpos_error2.phpt new file mode 100644 index 0000000..ea72322 --- /dev/null +++ b/ext/iconv/tests/iconv_strrpos_error2.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test iconv_strrpos() function : error conditions - pass an unknown encoding +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strrpos') or die("skip iconv_strrpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : proto int iconv_strrpos(string haystack, string needle [, string charset]) + * Description: Find position of last occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass iconv_strrpos() an encoding that doesn't exist + */ + +echo "*** Testing iconv_strrpos() : error conditions ***\n"; + +$haystack = 'This is an English string. 0123456789.'; +$needle = '123'; +$offset = 5; +$encoding = 'unknown-encoding'; + +var_dump(iconv_strrpos($haystack, $needle , $encoding)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_strrpos() : error conditions *** + +Notice: iconv_strrpos(): Wrong charset, conversion from `unknown-encoding' to `UCS-4LE' is not allowed in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_strrpos_variation1.phpt b/ext/iconv/tests/iconv_strrpos_variation1.phpt new file mode 100644 index 0000000..e4ed011 --- /dev/null +++ b/ext/iconv/tests/iconv_strrpos_variation1.phpt @@ -0,0 +1,180 @@ +--TEST-- +Test iconv_strrpos() function : usage variations - pass different data types to $haystack arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strrpos') or die("skip iconv_strrpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : proto int iconv_strrpos(string haystack, string needle [, string charset]) + * Description: Find position of last occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass iconv_strrpos() different data types as $haystack argument to test behaviour + */ + +echo "*** Testing iconv_strrpos() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$needle = 'world'; +$encoding = 'utf-8'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "hello, world"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello, world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $haystack argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "hello, world", + 'hello, world', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_strrpos() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_strrpos($input, $needle, $encoding)); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing iconv_strrpos() : usage variations *** + +-- Iteration 1 -- +bool(false) + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- +int(7) + +-- Iteration 19 -- +int(7) + +-- Iteration 20 -- +int(7) + +-- Iteration 21 -- +int(7) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- + +Warning: iconv_strrpos() expects parameter 1 to be string, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_strrpos_variation2.phpt b/ext/iconv/tests/iconv_strrpos_variation2.phpt new file mode 100644 index 0000000..a0001f5 --- /dev/null +++ b/ext/iconv/tests/iconv_strrpos_variation2.phpt @@ -0,0 +1,182 @@ +--TEST-- +Test iconv_strrpos() function : usage variations - Pass different data types to $needle arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strrpos') or die("skip iconv_strrpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : proto int iconv_strrpos(string haystack, string needle [, string charset]) + * Description: Find position of last occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass iconv_strrpos() different data types as $needle argument to test behaviour + */ + +echo "*** Testing iconv_strrpos() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$haystack = 'hello, world'; +$encoding = 'utf-8'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "world"; + } +} + +// heredoc string +$heredoc = <<<EOT +world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $needle argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "world", + 'world', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_strrpos() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_strrpos($haystack, $input, $encoding)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing iconv_strrpos() : usage variations *** + +-- Iteration 1 -- +bool(false) + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- +int(7) + +-- Iteration 19 -- +int(7) + +-- Iteration 20 -- +int(7) + +-- Iteration 21 -- +int(7) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- + +Warning: iconv_strrpos() expects parameter 2 to be string, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_strrpos_variation3.phpt b/ext/iconv/tests/iconv_strrpos_variation3.phpt new file mode 100644 index 0000000..87a21bd --- /dev/null +++ b/ext/iconv/tests/iconv_strrpos_variation3.phpt @@ -0,0 +1,205 @@ +--TEST-- +Test iconv_strrpos() function : usage variations - pass different data types as $encoding arg +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_strrpos') or die("skip iconv_strrpos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : proto int iconv_strrpos(string haystack, string needle [, string charset]) + * Description: Find position of last occurrence of a string within another + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass iconv_strrpos() different data types as $encoding argument to test behaviour + * Where possible 'UTF-8' has been entered as a string value + */ + +echo "*** Testing iconv_strrpos() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$haystack = b'hello, world'; +$needle = b'world'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "UTF-8"; + } +} + +// heredoc string +$heredoc = <<<EOT +UTF-8 +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $encoding argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "UTF-8", + 'UTF-8', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of iconv_strrpos() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( iconv_strrpos($haystack, $needle, $input)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing iconv_strrpos() : usage variations *** + +-- Iteration 1 -- + +Notice: iconv_strrpos(): Wrong charset, conversion from `0' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 2 -- + +Notice: iconv_strrpos(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 3 -- + +Notice: iconv_strrpos(): Wrong charset, conversion from `12345' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 4 -- + +Notice: iconv_strrpos(): Wrong charset, conversion from `-2345' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 5 -- + +Notice: iconv_strrpos(): Wrong charset, conversion from `10.5' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 6 -- + +Notice: iconv_strrpos(): Wrong charset, conversion from `-10.5' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 7 -- + +Notice: iconv_strrpos(): Wrong charset, conversion from `123456789000' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 8 -- + +Notice: iconv_strrpos(): Wrong charset, conversion from `1.23456789E-9' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 9 -- + +Notice: iconv_strrpos(): Wrong charset, conversion from `0.5' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 10 -- +int(7) + +-- Iteration 11 -- +int(7) + +-- Iteration 12 -- + +Notice: iconv_strrpos(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 13 -- +int(7) + +-- Iteration 14 -- + +Notice: iconv_strrpos(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d +bool(false) + +-- Iteration 15 -- +int(7) + +-- Iteration 16 -- +int(7) + +-- Iteration 17 -- +int(7) + +-- Iteration 18 -- +int(7) + +-- Iteration 19 -- +int(7) + +-- Iteration 20 -- +int(7) + +-- Iteration 21 -- +int(7) + +-- Iteration 22 -- +int(7) + +-- Iteration 23 -- +int(7) + +-- Iteration 24 -- + +Warning: iconv_strrpos() expects parameter 3 to be string, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/iconv/tests/iconv_substr-charset-length-cve-2007-4783.phpt b/ext/iconv/tests/iconv_substr-charset-length-cve-2007-4783.phpt new file mode 100644 index 0000000..c27e60d --- /dev/null +++ b/ext/iconv/tests/iconv_substr-charset-length-cve-2007-4783.phpt @@ -0,0 +1,14 @@ +--TEST-- +iconv_substr() charset parameter length checks (CVE-2007-4783) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--FILE-- +<?php +$a = str_repeat('A', 99897); +$b = str_repeat('/', 2798349); +var_dump(iconv_substr($a, 0, 1, $b)); +?> +--EXPECTF-- + +Warning: iconv_substr(): Charset parameter exceeds the maximum allowed length of %d characters in %s on line %d +bool(false) diff --git a/ext/iconv/tests/iconv_substr.phpt b/ext/iconv/tests/iconv_substr.phpt new file mode 100644 index 0000000..6ca545b --- /dev/null +++ b/ext/iconv/tests/iconv_substr.phpt @@ -0,0 +1,59 @@ +--TEST-- +iconv_substr() +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--INI-- +iconv.internal_charset=ISO-8859-1 +--FILE-- +<?php +function hexdump($str) { + $len = strlen($str); + for ($i = 0; $i < $len; ++$i) { + printf("%02x", ord($str[$i])); + } + print "\n"; +} + +function foo($str, $offset, $len, $charset) { + hexdump(substr($str, $offset, $len)); + hexdump(iconv_substr($str, $offset, $len, $charset)); +} + +function bar($str, $offset, $len = false) { + if (is_bool($len)) { + var_dump(substr($str, $offset)); + var_dump(iconv_substr($str, $offset)); + } else { + var_dump(substr($str, $offset, $len)); + var_dump(iconv_substr($str, $offset, $len)); + } +} + +foo("abcdefghijklmnopqrstuvwxyz", 5, 7, "ASCII"); +foo("", 5, 7, "EUC-JP"); +bar("This is a test", 100000); +bar("This is a test", 0, 100000); +bar("This is a test", -3); +bar("This is a test", 0, -9); +bar("This is a test", 0, -100000); +bar("This is a test", -9, -100000); +var_dump(iconv("ISO-2022-JP", "EUC-JP", iconv_substr(iconv("EUC-JP", "ISO-2022-JP", "ˤ ISO-2022-JP"), 3, 8, "ISO-2022-JP"))); +?> +--EXPECT-- +666768696a6b6c +666768696a6b6c +a6a4a8a4aaa4ab +a4aba4ada4afa4b1a4b3a4b5a4b7 +bool(false) +bool(false) +string(14) "This is a test" +string(14) "This is a test" +string(3) "est" +string(3) "est" +string(5) "This " +string(5) "This " +bool(false) +bool(false) +bool(false) +bool(false) +string(10) " ISO-2" diff --git a/ext/iconv/tests/iconv_substr_basic.phpt b/ext/iconv/tests/iconv_substr_basic.phpt new file mode 100644 index 0000000..0754fc8 --- /dev/null +++ b/ext/iconv/tests/iconv_substr_basic.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test iconv_substr() function : basic functionality +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_substr') or die("skip iconv_substr() is not available in this build"); +?> +--INI-- +iconv.input_encoding=ISO-8859-1 +iconv.internal_encoding=ISO-8859-1 +iconv.output_encoding=ISO-8859-1 +--FILE-- +<?php +/* Prototype : string iconv_substr(string str, int offset, [int length, string charset]) + * Description: Returns part of a string + * Source code: ext/iconv/iconv.c + */ + +/* + * Test Basic Functionality of iconv_substr with ASCII characters and multibyte strings. + */ + +echo "*** Testing iconv_substr() : basic functionality ***\n"; + +$string_ascii = b'ABCDEF'; +//Japanese string in UTF-8 +$string_mb = base64_decode(b'5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); + +echo "\n-- ASCII string 1 --\n"; +var_dump(bin2hex(iconv_substr($string_ascii, 3))); + +echo "\n-- ASCII string 2 --\n"; +var_dump(bin2hex(iconv_substr($string_ascii, 3, 5, 'ISO-8859-1'))); + +echo "\n-- Multibyte string 1 --\n"; +$result_1 = iconv_substr($string_mb, 2, 7); +var_dump(bin2hex($result_1)); + +echo "\n-- Multibyte string 2 --\n"; +$result_2 = iconv_substr($string_mb, 2, 7, 'utf-8'); +var_dump(bin2hex($result_2)); + +echo "Done"; +?> +--EXPECT-- +*** Testing iconv_substr() : basic functionality *** + +-- ASCII string 1 -- +string(6) "444546" + +-- ASCII string 2 -- +string(6) "444546" + +-- Multibyte string 1 -- +string(14) "a5e69cace8aa9e" + +-- Multibyte string 2 -- +string(42) "e8aa9ee38386e382ade382b9e38388e381a7e38199" +Done diff --git a/ext/iconv/tests/iconv_substr_error1.phpt b/ext/iconv/tests/iconv_substr_error1.phpt new file mode 100644 index 0000000..7a30c7d --- /dev/null +++ b/ext/iconv/tests/iconv_substr_error1.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test iconv_substr() function : error conditions - Pass incorrect number of args +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_substr') or die("skip iconv_substr() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : string iconv_substr(string str, int offset, [int length, string charset]) + * Description: Returns part of a string + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass incorrect number of arguments to iconv_substr() to test behaviour + */ + +echo "*** Testing iconv_substr() : error conditions ***\n"; + +//Test iconv_substr with one more than the expected number of arguments +echo "\n-- Testing iconv_substr() function with more than expected no. of arguments --\n"; +$str = 'string_val'; +$start = 10; +$length = 10; +$encoding = 'string_val'; +$extra_arg = 10; +var_dump( iconv_substr($str, $start, $length, $encoding, $extra_arg) ); + +// Testing iconv_substr with one less than the expected number of arguments +echo "\n-- Testing iconv_substr() function with less than expected no. of arguments --\n"; +$str = 'string_val'; +var_dump( iconv_substr($str) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_substr() : error conditions *** + +-- Testing iconv_substr() function with more than expected no. of arguments -- + +Warning: iconv_substr() expects at most 4 parameters, 5 given in %s on line %d +bool(false) + +-- Testing iconv_substr() function with less than expected no. of arguments -- + +Warning: iconv_substr() expects at least 2 parameters, 1 given in %s on line %d +bool(false) +Done + diff --git a/ext/iconv/tests/iconv_substr_error2.phpt b/ext/iconv/tests/iconv_substr_error2.phpt new file mode 100644 index 0000000..ac50813 --- /dev/null +++ b/ext/iconv/tests/iconv_substr_error2.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test iconv_substr() function : error conditions - Pass an unknown encoding +--SKIPIF-- +<?php +extension_loaded('iconv') or die('skip'); +function_exists('iconv_substr') or die("skip iconv_substr() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : string iconv_substr(string str, int offset, [int length, string charset]) + * Description: Returns part of a string + * Source code: ext/iconv/iconv.c + */ + +/* + * Pass an unknown encoding to iconv_substr() to test behaviour + */ + +echo "*** Testing iconv_substr() : error conditions ***\n"; + +$str = 'Hello, world'; +$start = 1; +$length = 5; +$encoding = 'unknown-encoding'; + +var_dump( iconv_substr($str, $start, $length, $encoding)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing iconv_substr() : error conditions *** + +Notice: iconv_substr(): Wrong charset, conversion from `unknown-encoding' to `UCS-4LE' is not allowed in %s on line %d +bool(false) +Done + diff --git a/ext/iconv/tests/ob_iconv_handler-charset-length-cve-2007-4840.phpt b/ext/iconv/tests/ob_iconv_handler-charset-length-cve-2007-4840.phpt new file mode 100644 index 0000000..fd01d83 --- /dev/null +++ b/ext/iconv/tests/ob_iconv_handler-charset-length-cve-2007-4840.phpt @@ -0,0 +1,14 @@ +--TEST-- +ob_iconv_handler() charset parameter length checks (CVE-2007-4840) +--SKIPIF-- +<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> +--INI-- +memory_limit=256M +--FILE-- +<?php +ini_set("iconv.output_encoding", str_repeat("a", 9000000)); +ob_start("ob_iconv_handler"); +print "done"; +?> +--EXPECT-- +done diff --git a/ext/iconv/tests/ob_iconv_handler.phpt b/ext/iconv/tests/ob_iconv_handler.phpt new file mode 100644 index 0000000..20f9169 --- /dev/null +++ b/ext/iconv/tests/ob_iconv_handler.phpt @@ -0,0 +1,17 @@ +--TEST-- +ob_iconv_handler() +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +error_reporting=2039 +--FILE-- +<?php +/* include('test.inc'); */ +iconv_set_encoding('internal_encoding', 'EUC-JP'); +iconv_set_encoding('output_encoding', 'Shift_JIS'); +ob_start('ob_iconv_handler'); +print ""; +ob_end_flush(); +?> +--EXPECT-- + diff --git a/ext/iconv/tests/skipif.inc b/ext/iconv/tests/skipif.inc new file mode 100644 index 0000000..70d0067 --- /dev/null +++ b/ext/iconv/tests/skipif.inc @@ -0,0 +1,5 @@ +<?php +if (!extension_loaded("iconv")) { + die("skip iconv extension not available\n"); +} +?> diff --git a/ext/iconv/tests/test.inc b/ext/iconv/tests/test.inc new file mode 100644 index 0000000..78f1804 --- /dev/null +++ b/ext/iconv/tests/test.inc @@ -0,0 +1,7 @@ +<?php +// Do not dl load extension +//if (!extension_loaded("iconv") && ini_get("enable_dl")) { +// $dlext = (substr(PHP_OS, 0, 3) == "WIN") ? ".dll" : ".so"; +// @dl("iconv$dlext"); +//} +?>
\ No newline at end of file diff --git a/ext/iconv/tests/translit-failure.phpt b/ext/iconv/tests/translit-failure.phpt new file mode 100644 index 0000000..d8b9fbf --- /dev/null +++ b/ext/iconv/tests/translit-failure.phpt @@ -0,0 +1,31 @@ +--TEST-- +Translit failure +--SKIPIF-- +<?php +include('skipif.inc'); +( ICONV_IMPL != "libiconv" ) and die("skip ICONV_IMPL != \"libiconv\""); +?> +--INI-- +error_reporting=2039 +--FILE-- +<?php +/* include('test.inc'); */ +// Should be ok. +// Content from file is from libiconv testkit. Tested both +// with a string as an implode, no difference. +// if at some point internal encoding changes, set correct one +// in INI section or use file 'TranslitFail1.ISO-8859-1'. + +set_time_limit(5); +/* + * The bug (fixed in libiconv 1.8) was confirmed that iconv goes into an + * infinite loop when ASCII//TRANSLIT is performed. We should stop it in + * some time. + */ + +$test = 'crit par %s.'; + +var_dump(iconv("ISO-8859-1", "ASCII//TRANSLIT", $test)); +?> +--EXPECT-- +string(14) "'Ecrit par %s." diff --git a/ext/iconv/tests/translit-utf8.phpt b/ext/iconv/tests/translit-utf8.phpt new file mode 100644 index 0000000..0151dc3 --- /dev/null +++ b/ext/iconv/tests/translit-utf8.phpt @@ -0,0 +1,27 @@ +--TEST-- +Translit UTF-8 quotes +--SKIPIF-- +<?php +include('skipif.inc'); +( ICONV_IMPL != "libiconv" ) and die("skip ICONV_IMPL != \"libiconv\""); +?> +--INI-- +error_reporting=2047 +--FILE-- +<?php // vim600: syn=php +/* include('test.inc'); */ +//error_reporting(E_ALL); +$utf = implode('', file(dirname(__FILE__).'/Quotes.UTF-8')); + +print(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $utf)); +print(iconv("UTF-8", "ASCII//TRANSLIT", $utf)); +?> +--EXPECT-- +"Hello" +`Hello +"Hello" +`Hello +"Hello" +'Hello' +"Hello" +'Hello' |