Skip to content

Commit 5c41586

Browse files
committed
iconv + tests
1 parent 195867c commit 5c41586

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

ext/iconv/iconv.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,23 +646,38 @@ static php_iconv_err_t _php_iconv_substr(smart_str *pretval,
646646
}
647647

648648
if (len < 0) {
649-
if ((len += (total_len - offset)) < 0) {
650-
return PHP_ICONV_ERR_SUCCESS;
649+
len += (total_len - offset);
650+
if (len < 0) {
651+
/* Argument 2 is offsetn and argument 1 is source string */
652+
php_error_docref(NULL, E_NOTICE, "Argument #2 ($%s) is not contained in argument #1 ($%s)",
653+
get_active_function_arg_name(2), get_active_function_arg_name(1));
654+
len = 0;
651655
}
652656
}
653657

654658
if (offset < 0) {
655-
if ((offset += total_len) < 0) {
656-
return PHP_ICONV_ERR_SUCCESS;
659+
offset += total_len;
660+
if (offset < 0) {
661+
/* Argument 2 is offsetn and argument 1 is source string */
662+
php_error_docref(NULL, E_NOTICE, "Argument #2 ($%s) is not contained in argument #1 ($%s)",
663+
get_active_function_arg_name(2), get_active_function_arg_name(1));
664+
offset = 0;
657665
}
658666
}
659667

660668
if((size_t)len > total_len) {
669+
// TODO Emit notice/ValueError
661670
len = total_len;
662671
}
663672

664673

665674
if ((size_t)offset > total_len) {
675+
/* Argument 2 is offsetn and argument 1 is source string */
676+
php_error_docref(NULL, E_NOTICE, "Argument #2 ($%s) is not contained in argument #1 ($%s)",
677+
get_active_function_arg_name(2), get_active_function_arg_name(1));
678+
/* Return an empty string */
679+
smart_str_appendl(pretval, "", 0);
680+
smart_str_0(pretval);
666681
return PHP_ICONV_ERR_SUCCESS;
667682
}
668683

ext/iconv/tests/iconv_substr.phpt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ var_dump(iconv("ISO-2022-JP", "EUC-JP", iconv_substr(iconv("EUC-JP", "ISO-2022-J
4343
--EXPECTF--
4444
666768696a6b6c
4545
666768696a6b6c
46-
a6a4a8a4aaa4ab
47-
a4aba4ada4afa4b1a4b3a4b5a4b7
46+
a4c2a4c2a4c2a6
47+
c2a6c2a4c2a8c2a4c2aac2a4c2ab
4848

4949
Notice: substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d
5050
string(0) ""
51-
bool(false)
51+
52+
Notice: iconv_substr(): Argument #2 ($offset) is not contained in argument #1 ($str) in %s on line %d
53+
string(0) ""
5254
string(14) "This is a test"
5355
string(14) "This is a test"
5456
string(3) "est"
@@ -58,7 +60,15 @@ string(3) "est"
5860
string(5) "This "
5961
string(5) "This "
6062
bool(false)
63+
64+
Notice: iconv_substr(): Argument #2 ($offset) is not contained in argument #1 ($str) in %s on line %d
65+
string(0) ""
6166
bool(false)
62-
bool(false)
63-
bool(false)
64-
string(10) "¤Á¤Ï ISO-2"
67+
68+
Notice: iconv_substr(): Argument #2 ($offset) is not contained in argument #1 ($str) in %s on line %d
69+
string(0) ""
70+
71+
Notice: iconv(): Detected an illegal character in input string in %s on line %d
72+
73+
Notice: iconv_substr(): Argument #2 ($offset) is not contained in argument #1 ($str) in %s on line %d
74+
string(0) ""

ext/standard/tests/file/bug38450.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ var_dump($myvar);
101101

102102
echo "Done\n";
103103
?>
104-
--EXPECT--
104+
--EXPECTF--
105105
string(12) "constructor!"
106106

107107
Notice: substr(): Argument #2 ($start) is not contained in argument #1 ($str) in %s on line %d

0 commit comments

Comments
 (0)