From f729f606120d6d609e5fc978c09988340992fab4 Mon Sep 17 00:00:00 2001 From: Tank Tang Date: Thu, 21 Mar 2019 19:08:20 +0800 Subject: [PATCH] Fixed a bug where blob/file name '0' can not be created. --- azure-storage-blob/src/Blob/BlobRestProxy.php | 2 +- azure-storage-common/src/Common/Internal/Validate.php | 2 +- azure-storage-file/src/File/FileRestProxy.php | 2 +- tests/Functional/File/FileServiceFunctionalTest.php | 11 +++++++++++ tests/Unit/Common/Internal/ValidateTest.php | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/azure-storage-blob/src/Blob/BlobRestProxy.php b/azure-storage-blob/src/Blob/BlobRestProxy.php index 20a4d94a8..67104efb1 100644 --- a/azure-storage-blob/src/Blob/BlobRestProxy.php +++ b/azure-storage-blob/src/Blob/BlobRestProxy.php @@ -347,7 +347,7 @@ private function getCopyBlobSourceName( */ private function createPath($container, $blob = '') { - if (empty($blob)) { + if (empty($blob) && ($blob != '0')) { return empty($container) ? '/' : $container; } $encodedBlob = urlencode($blob); diff --git a/azure-storage-common/src/Common/Internal/Validate.php b/azure-storage-common/src/Common/Internal/Validate.php index 74e9e05ca..4517e7da0 100644 --- a/azure-storage-common/src/Common/Internal/Validate.php +++ b/azure-storage-common/src/Common/Internal/Validate.php @@ -101,7 +101,7 @@ public static function isBoolean($var) */ public static function notNullOrEmpty($var, $name) { - if (is_null($var) || empty($var)) { + if (is_null($var) || (empty($var) && $var != '0')) { throw new \InvalidArgumentException( sprintf(Resources::NULL_OR_EMPTY_MSG, $name) ); diff --git a/azure-storage-file/src/File/FileRestProxy.php b/azure-storage-file/src/File/FileRestProxy.php index b8fec9488..456e002a1 100644 --- a/azure-storage-file/src/File/FileRestProxy.php +++ b/azure-storage-file/src/File/FileRestProxy.php @@ -153,7 +153,7 @@ public static function createFileService( */ private function createPath($share, $directory = '') { - if (empty($directory)) { + if (empty($directory) && ($directory != '0')) { return empty($share) ? '/' : $share; } $encodedFile = urlencode($directory); diff --git a/tests/Functional/File/FileServiceFunctionalTest.php b/tests/Functional/File/FileServiceFunctionalTest.php index c015ba851..bdcede468 100644 --- a/tests/Functional/File/FileServiceFunctionalTest.php +++ b/tests/Functional/File/FileServiceFunctionalTest.php @@ -1655,6 +1655,17 @@ public function testPutListClearRanges() $this->safeDeleteShare($share); } + public function testCreateFileWithNameIsZero() + { + $share = FileServiceFunctionalTestData::getInterestingShareName(); + $this->safeCreateShare($share); + $file = '0'; + $this->restProxy->createFile($share, $file, 2048); + $res = $this->restProxy->getFileProperties($share, $file); + $this->assertEquals(2048, $res->getContentLength()); + $this->safeDeleteShare($share); + } + private function putListClearRangesWorker( $share, $file, diff --git a/tests/Unit/Common/Internal/ValidateTest.php b/tests/Unit/Common/Internal/ValidateTest.php index 6fa0fbf7b..839ba205b 100644 --- a/tests/Unit/Common/Internal/ValidateTest.php +++ b/tests/Unit/Common/Internal/ValidateTest.php @@ -117,6 +117,7 @@ public function testIsDateWithNonDate() public function testNotNullOrEmptyWithNonEmpty() { Validate::notNullOrEmpty(1234, 'not null'); + Validate::notNullOrEmpty('0', 'not null'); $this->assertTrue(true); }