From c6ad1b5aaabfa9b4ae71e43f95496f517de0406c Mon Sep 17 00:00:00 2001 From: Andrew Berry Date: Thu, 9 Jul 2015 20:43:41 -0400 Subject: [PATCH] Issue #2502601: Fix notice on getExternalUri with no object key --- src/StreamWrapper.php | 2 +- tests/StreamWrapperTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/StreamWrapper.php b/src/StreamWrapper.php index c79ef3f..af5ebe3 100644 --- a/src/StreamWrapper.php +++ b/src/StreamWrapper.php @@ -218,7 +218,7 @@ public function getExternalUrl() { // Delivers the first request to an image from the private file system // otherwise it returns an external URL to an image that has not been // created yet. - if ($path_segments[0] === 'styles' && !file_exists((string) $this->uri)) { + if (!empty($path_segments) && $path_segments[0] === 'styles' && !file_exists((string) $this->uri)) { return $this->url($this::stylesCallback . '/' . $this->uri->getBucket() . $this->uri->getPath(), array('absolute' => TRUE)); } diff --git a/tests/StreamWrapperTest.php b/tests/StreamWrapperTest.php index c490a6b..c795a74 100644 --- a/tests/StreamWrapperTest.php +++ b/tests/StreamWrapperTest.php @@ -210,6 +210,17 @@ public function testExternalUri() { $this->assertEquals('https://s3.amazonaws.com/bucket.example.com/image.jpg', $wrapper->getExternalUrl()); } + /** + * Test that we can call getExternalUrl() when no key has been specified. + * + * @covers \Drupal\amazons3\StreamWrapper::getExternalUrl + */ + public function testExternalUriEmptyPathSegments() { + $wrapper = new StreamWrapper(); + $wrapper->setUri('s3://bucket.example.com/'); + $this->assertEquals('https://s3.amazonaws.com/bucket.example.com', $wrapper->getExternalUrl()); + } + /** * Test getting a mime type. *