Skip to content

Commit

Permalink
Avoid accidental filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed May 8, 2019
1 parent 2407fc5 commit d629070
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/MemoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function deleteDir($dirname)
*/
public function getMetadata($path)
{
$metadata = array_filter($this->storage[$path]) + ['path' => $path];
$metadata = $this->storage[$path] + ['path' => $path];
unset($metadata['contents']);

return $metadata;
Expand All @@ -105,7 +105,8 @@ public function getMetadata($path)
*/
public function getMimetype($path)
{
$mimetype = $this->storage[$path]['mimetype'] ?: Util::guessMimeType($path, $this->storage[$path]['contents']);
$mimetype = isset($this->storage[$path]['mimetype']) ? $this->storage[$path]['mimetype'] :
Util::guessMimeType($path, $this->storage[$path]['contents']);

return [
'mimetype' => $mimetype,
Expand Down Expand Up @@ -223,7 +224,9 @@ public function update($path, $contents, Config $config)
$this->storage[$path]['timestamp'] = $config->get('timestamp', time());
$this->storage[$path]['size'] = Util::contentSize($contents);
$this->storage[$path]['visibility'] = $config->get('visibility', $this->storage[$path]['visibility']);
$this->storage[$path]['mimetype'] = $config->get('mimetype');
if ($config->has('mimetype')) {
$this->storage[$path]['mimetype'] = $config->get('mimetype');
}

return $this->getMetadata($path);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/MemoryAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testGetMetadata()
$this->assertSame('public', $meta['visibility']);
$this->assertTrue(is_int($meta['timestamp']));

$this->adapter->write('dir/file.txt', 'contents', new Config(['mimetype' => 'mime/type']));
$this->adapter->write('dir/file.txt', '', new Config(['mimetype' => 'mime/type']));

$meta = $this->adapter->getMetadata('dir/file.txt');

Expand Down

0 comments on commit d629070

Please sign in to comment.