Skip to content

Commit 4095c0a

Browse files
committed
Promote empty filename to ValueError in BZ2 extension
1 parent c3105a1 commit 4095c0a

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

ext/bz2/bz2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ PHP_FUNCTION(bzopen)
350350
/* If it's not a resource its a string containing the filename to open */
351351
if (Z_TYPE_P(file) == IS_STRING) {
352352
if (Z_STRLEN_P(file) == 0) {
353-
php_error_docref(NULL, E_WARNING, "Filename cannot be empty");
353+
zend_argument_value_error(1, "cannot be empty");
354354
RETURN_FALSE;
355355
}
356356

ext/bz2/tests/001.phpt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,45 @@ bzopen() and invalid parameters
66
<?php
77

88
try {
9-
var_dump(bzopen("", ""));
9+
var_dump(bzopen("", "r"));
1010
} catch (\ValueError $e) {
1111
echo $e->getMessage() . \PHP_EOL;
1212
}
1313

14-
var_dump(bzopen("", "r"));
15-
var_dump(bzopen("", "w"));
14+
try {
15+
var_dump(bzopen("", "w"));
16+
} catch (\ValueError $e) {
17+
echo $e->getMessage() . \PHP_EOL;
18+
}
1619

1720
try {
18-
var_dump(bzopen("", "x"));
21+
var_dump(bzopen("no_such_file", ""));
1922
} catch (\ValueError $e) {
2023
echo $e->getMessage() . \PHP_EOL;
2124
}
2225

2326
try {
24-
var_dump(bzopen("", "rw"));
27+
var_dump(bzopen("no_such_file", "x"));
2528
} catch (\ValueError $e) {
2629
echo $e->getMessage() . \PHP_EOL;
2730
}
2831

2932
try {
30-
var_dump(bzopen("no_such_file", "r"));
33+
var_dump(bzopen("no_such_file", "rw"));
3134
} catch (\ValueError $e) {
3235
echo $e->getMessage() . \PHP_EOL;
3336
}
3437

38+
var_dump(bzopen("no_such_file", "r"));
39+
3540
$fp = fopen(__FILE__,"r");
3641
var_dump(bzopen($fp, "r"));
3742

3843
?>
3944
--EXPECTF--
45+
bzopen(): Argument #1 ($file) cannot be empty
46+
bzopen(): Argument #1 ($file) cannot be empty
4047
bzopen(): Argument #2 ($mode) must be either "r" or "w"
41-
42-
Warning: bzopen(): Filename cannot be empty in %s on line %d
43-
bool(false)
44-
45-
Warning: bzopen(): Filename cannot be empty in %s on line %d
46-
bool(false)
4748
bzopen(): Argument #2 ($mode) must be either "r" or "w"
4849
bzopen(): Argument #2 ($mode) must be either "r" or "w"
4950

0 commit comments

Comments
 (0)