Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/iceberg/catalog/rest/resource_paths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Result<std::unique_ptr<ResourcePaths>> ResourcePaths::Make(
if (base_uri.empty()) {
return InvalidArgument("Base URI is empty");
}
ICEBERG_PRECHECK(!namespace_separator.empty(),
"REST namespace separator cannot be empty");
return std::unique_ptr<ResourcePaths>(
new ResourcePaths(std::move(base_uri), prefix, namespace_separator));
}
Expand Down
13 changes: 13 additions & 0 deletions src/iceberg/catalog/rest/rest_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@

namespace iceberg::rest {

namespace {

Status ValidateNamespaceSeparator(std::string_view separator) {
ICEBERG_PRECHECK(!separator.empty(), "REST namespace separator cannot be empty");
return {};
}

} // namespace

std::string_view TrimTrailingSlash(std::string_view str) {
while (!str.empty() && str.back() == '/') {
str.remove_suffix(1);
Expand Down Expand Up @@ -67,6 +76,8 @@ Result<std::string> DecodeString(std::string_view str_to_decode) {

Result<std::string> EncodeNamespace(const Namespace& ns_to_encode,
std::string_view separator) {
ICEBERG_RETURN_UNEXPECTED(ValidateNamespaceSeparator(separator));

if (ns_to_encode.levels.empty()) {
return "";
}
Expand All @@ -85,6 +96,8 @@ Result<std::string> EncodeNamespace(const Namespace& ns_to_encode,

Result<Namespace> DecodeNamespace(std::string_view str_to_decode,
std::string_view separator) {
ICEBERG_RETURN_UNEXPECTED(ValidateNamespaceSeparator(separator));

if (str_to_decode.empty()) {
return Namespace{.levels = {}};
}
Expand Down
20 changes: 20 additions & 0 deletions src/iceberg/test/rest_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "iceberg/catalog/rest/catalog_properties.h"
#include "iceberg/catalog/rest/endpoint.h"
#include "iceberg/catalog/rest/resource_paths.h"
#include "iceberg/table_identifier.h"
#include "iceberg/test/matchers.h"

Expand Down Expand Up @@ -83,6 +84,25 @@ TEST(RestUtilTest, RoundTripNamespaceWithCustomSeparator) {
HasValue(::testing::Eq(ns)));
}

TEST(RestUtilTest, NamespaceRejectsEmptySeparator) {
auto expect_empty_separator_error = [](const auto& result) {
EXPECT_THAT(result, IsError(ErrorKind::kInvalidArgument));
EXPECT_THAT(result, HasErrorMessage("REST namespace separator cannot be empty"));
};

expect_empty_separator_error(EncodeNamespace(Namespace{.levels = {"dogs"}}, ""));
expect_empty_separator_error(EncodeNamespace(Namespace{.levels = {}}, ""));
expect_empty_separator_error(DecodeNamespace("dogs", ""));
expect_empty_separator_error(DecodeNamespace("", ""));
}

TEST(RestUtilTest, ResourcePathsRejectsEmptyNamespaceSeparator) {
auto result = ResourcePaths::Make("https://catalog.example.com", "", "");

EXPECT_THAT(result, IsError(ErrorKind::kInvalidArgument));
EXPECT_THAT(result, HasErrorMessage("REST namespace separator cannot be empty"));
}

TEST(RestUtilTest, EncodeString) {
// RFC 3986 unreserved characters should not be encoded
EXPECT_THAT(EncodeString("abc123XYZ"), HasValue(::testing::Eq("abc123XYZ")));
Expand Down
Loading