Skip to content

Commit be11563

Browse files
committed
Merge branch 'PHP-7.0' into PHP-7.1
2 parents fab1815 + 23c359c commit be11563

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ PHP NEWS
2929
- SQLite3:
3030
. Fixed bug #72668 (Spurious warning when exception is thrown in user defined
3131
function). (Laruence)
32+
. Implemented FR #72653 (SQLite should allow opening with empty filename).
33+
(cmb)
3234

3335
- Streams:
3436
. Fixed bug #41021 (Problems with the ftps wrapper). (vhuk)

ext/sqlite3/sqlite3.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,11 @@ PHP_METHOD(sqlite3, open)
112112

113113
if (db_obj->initialised) {
114114
zend_throw_exception(zend_ce_exception, "Already initialised DB Object", 0);
115-
}
116-
117-
if (strlen(filename) != filename_len) {
118115
return;
119116
}
120-
if (filename_len != sizeof(":memory:")-1 ||
121-
memcmp(filename, ":memory:", sizeof(":memory:")-1) != 0) {
117+
118+
if (filename_len != 0 && (filename_len != sizeof(":memory:")-1 ||
119+
memcmp(filename, ":memory:", sizeof(":memory:")-1) != 0)) {
122120
if (!(fullpath = expand_filepath(filename, NULL))) {
123121
zend_throw_exception(zend_ce_exception, "Unable to expand filepath", 0);
124122
return;
@@ -130,7 +128,8 @@ PHP_METHOD(sqlite3, open)
130128
return;
131129
}
132130
} else {
133-
fullpath = estrdup(filename);
131+
/* filename equals "" or ":memory:" */
132+
fullpath = filename;
134133
}
135134

136135
#if SQLITE_VERSION_NUMBER >= 3005000
@@ -139,7 +138,7 @@ PHP_METHOD(sqlite3, open)
139138
if (sqlite3_open(fullpath, &(db_obj->db)) != SQLITE_OK) {
140139
#endif
141140
zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s", sqlite3_errmsg(db_obj->db));
142-
if (fullpath) {
141+
if (fullpath != filename) {
143142
efree(fullpath);
144143
}
145144
return;
@@ -160,7 +159,7 @@ PHP_METHOD(sqlite3, open)
160159
sqlite3_set_authorizer(db_obj->db, php_sqlite3_authorizer, NULL);
161160
}
162161

163-
if (fullpath) {
162+
if (fullpath != filename) {
164163
efree(fullpath);
165164
}
166165
}

ext/sqlite3/tests/sqlite3_open_empty_string.phpt

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ Thijs Feryn <[email protected]>
77
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
88
--FILE--
99
<?php
10-
try{
11-
$db = new SQLite3('');
12-
} catch(Exception $e) {
13-
echo $e->getMessage().PHP_EOL;
14-
}
10+
$db = new SQLite3('');
1511
echo "Done\n";
1612
?>
17-
--EXPECTF--
18-
Unable to expand filepath
13+
--EXPECT--
1914
Done

0 commit comments

Comments
 (0)