diff --git a/res/sqlite-worker.php b/res/sqlite-worker.php index 30d43df..a010a32 100644 --- a/res/sqlite-worker.php +++ b/res/sqlite-worker.php @@ -90,6 +90,11 @@ 'id' => $data->id, 'error' => array('message' => $e->getMessage()) )); + } catch (Error $e) { + $out->write(array( + 'id' => $data->id, + 'error' => array('message' => $e->getMessage()) + )); } } elseif ($data->method === 'open' && \count($data->params) === 2 && \is_string($data->params[0]) && \is_int($data->params[1])) { // open database with two parameters: $filename, $flags @@ -108,6 +113,11 @@ 'id' => $data->id, 'error' => array('message' => $e->getMessage()) )); + } catch (Error $e) { + $out->write(array( + 'id' => $data->id, + 'error' => array('message' => $e->getMessage()) + )); } } elseif ($data->method === 'exec' && $db !== null && \count($data->params) === 1 && \is_string($data->params[0])) { // execute statement and suppress PHP warnings diff --git a/tests/FunctionalDatabaseTest.php b/tests/FunctionalDatabaseTest.php index ba89b1b..adb1e66 100644 --- a/tests/FunctionalDatabaseTest.php +++ b/tests/FunctionalDatabaseTest.php @@ -134,6 +134,29 @@ public function testOpenInvalidPathRejects($flag) $loop->run(); } + /** + * @dataProvider provideSocketFlags + * @param bool $flag + */ + public function testOpenInvalidPathWithNullByteRejects($flag) + { + $loop = \React\EventLoop\Factory::create(); + $factory = new Factory($loop); + + $ref = new \ReflectionProperty($factory, 'useSocket'); + $ref->setAccessible(true); + $ref->setValue($factory, $flag); + + $promise = $factory->open("test\0.db"); + + $promise->then( + null, + $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')) + ); + + $loop->run(); + } + /** * @dataProvider provideSocketFlags * @param bool $flag