diff --git a/cpp/src/arrow/filesystem/azurefs.cc b/cpp/src/arrow/filesystem/azurefs.cc index 4065b82c6c390..040e96f6f8e5c 100644 --- a/cpp/src/arrow/filesystem/azurefs.cc +++ b/cpp/src/arrow/filesystem/azurefs.cc @@ -340,6 +340,7 @@ class AzureFileSystem::Impl { Result> OpenInputFile(const std::string& s, AzureFileSystem* fs) { + ARROW_RETURN_NOT_OK(internal::AssertNoTrailingSlash(s)); ARROW_ASSIGN_OR_RAISE(auto path, AzurePath::FromString(s)); RETURN_NOT_OK(ValidateFilePath(path)); auto blob_client = std::make_shared( @@ -353,6 +354,7 @@ class AzureFileSystem::Impl { Result> OpenInputFile(const FileInfo& info, AzureFileSystem* fs) { + ARROW_RETURN_NOT_OK(internal::AssertNoTrailingSlash(info.path())); if (info.type() == FileType::NotFound) { return ::arrow::fs::internal::PathNotFound(info.path()); } diff --git a/cpp/src/arrow/filesystem/azurefs_test.cc b/cpp/src/arrow/filesystem/azurefs_test.cc index 355ed6ad24b3a..ecf57522c18d9 100644 --- a/cpp/src/arrow/filesystem/azurefs_test.cc +++ b/cpp/src/arrow/filesystem/azurefs_test.cc @@ -300,6 +300,10 @@ TEST_F(TestAzureFileSystem, OpenInputStreamUri) { ASSERT_RAISES(Invalid, fs_->OpenInputStream("abfss://" + PreexistingObjectPath())); } +TEST_F(TestAzureFileSystem, OpenInputStreamTrailingSlash) { + ASSERT_RAISES(IOError, fs_->OpenInputStream(PreexistingObjectPath() + '/')); +} + TEST_F(TestAzureFileSystem, OpenInputStreamReadMetadata) { const std::string object_name = "OpenInputStreamMetadataTest/simple.txt";