Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Commit f729f60

Browse files
katmsftvinjiang
authored andcommitted
Fixed a bug where blob/file name '0' can not be created.
1 parent 3357c7d commit f729f60

5 files changed

Lines changed: 15 additions & 3 deletions

File tree

azure-storage-blob/src/Blob/BlobRestProxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ private function getCopyBlobSourceName(
347347
*/
348348
private function createPath($container, $blob = '')
349349
{
350-
if (empty($blob)) {
350+
if (empty($blob) && ($blob != '0')) {
351351
return empty($container) ? '/' : $container;
352352
}
353353
$encodedBlob = urlencode($blob);

azure-storage-common/src/Common/Internal/Validate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static function isBoolean($var)
101101
*/
102102
public static function notNullOrEmpty($var, $name)
103103
{
104-
if (is_null($var) || empty($var)) {
104+
if (is_null($var) || (empty($var) && $var != '0')) {
105105
throw new \InvalidArgumentException(
106106
sprintf(Resources::NULL_OR_EMPTY_MSG, $name)
107107
);

azure-storage-file/src/File/FileRestProxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public static function createFileService(
153153
*/
154154
private function createPath($share, $directory = '')
155155
{
156-
if (empty($directory)) {
156+
if (empty($directory) && ($directory != '0')) {
157157
return empty($share) ? '/' : $share;
158158
}
159159
$encodedFile = urlencode($directory);

tests/Functional/File/FileServiceFunctionalTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,17 @@ public function testPutListClearRanges()
16551655
$this->safeDeleteShare($share);
16561656
}
16571657

1658+
public function testCreateFileWithNameIsZero()
1659+
{
1660+
$share = FileServiceFunctionalTestData::getInterestingShareName();
1661+
$this->safeCreateShare($share);
1662+
$file = '0';
1663+
$this->restProxy->createFile($share, $file, 2048);
1664+
$res = $this->restProxy->getFileProperties($share, $file);
1665+
$this->assertEquals(2048, $res->getContentLength());
1666+
$this->safeDeleteShare($share);
1667+
}
1668+
16581669
private function putListClearRangesWorker(
16591670
$share,
16601671
$file,

tests/Unit/Common/Internal/ValidateTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public function testIsDateWithNonDate()
117117
public function testNotNullOrEmptyWithNonEmpty()
118118
{
119119
Validate::notNullOrEmpty(1234, 'not null');
120+
Validate::notNullOrEmpty('0', 'not null');
120121

121122
$this->assertTrue(true);
122123
}

0 commit comments

Comments
 (0)