Skip to content

Commit 556c8f9

Browse files
committed
Test: Check for existence before opening file
1 parent c037889 commit 556c8f9

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

kernel/read.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ xlsxioreader file_open(const char *directory, const char *file_name) {
2828
php_stat(path, strlen(path), FS_IS_FILE, &file_exists);
2929

3030
if (Z_TYPE(file_exists) == IS_FALSE) {
31+
efree(path);
3132
zval_ptr_dtor(&file_exists);
3233
zend_throw_exception(vtiful_exception_ce, "File not found, please check the path in the config or file name", 121);
34+
return NULL;
3335
}
3436

3537
if ((file = xlsxioread_open(path)) == NULL) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php
5+
require __DIR__ . '/include/skipif.inc';
6+
skip_disable_reader();
7+
?>
8+
--FILE--
9+
<?php
10+
try {
11+
$config = ['path' => './tests'];
12+
$excel = new \Vtiful\Kernel\Excel($config);
13+
14+
$excel->openFile('tutorial_not_found.xlsx');
15+
} catch (Vtiful\Kernel\Exception $exception) {
16+
var_dump($exception->getMessage());
17+
}
18+
?>
19+
--CLEAN--
20+
<?php
21+
//
22+
?>
23+
--EXPECT--
24+
string(64) "File not found, please check the path in the config or file name"

0 commit comments

Comments
 (0)