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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix removing attachments with numeric keys, [PR-113](https://github.com/reductstore/reduct-cpp/pull/113)
- Fix removing attachments with reserved `$`-prefixed keys, [PR-115](https://github.com/reductstore/reduct-cpp/pull/115)

## 1.18.0 - 2026-02-04

Expand Down
17 changes: 15 additions & 2 deletions src/reduct/bucket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <optional>
#include <set>
#include <thread>
#include <vector>

#include "reduct/internal/batch_v1.h"
#include "reduct/internal/batch_v2.h"
Expand Down Expand Up @@ -251,11 +252,23 @@ class Bucket : public IBucket {
const std::set<std::string>& attachment_keys) const noexcept override {
QueryOptions options;
if (!attachment_keys.empty()) {
std::vector<std::string> escaped_keys;
Comment thread
atimin marked this conversation as resolved.
Comment thread
atimin marked this conversation as resolved.
escaped_keys.reserve(attachment_keys.size());
for (const auto& key : attachment_keys) {
// Keys starting with '$' must be escaped so the server treats them as literals
// instead of interpreting them as messagepack filter operators.
if (!key.empty() && key.front() == '$') {
escaped_keys.emplace_back(fmt::format("${}", key));
} else {
escaped_keys.emplace_back(key);
}
}

nlohmann::json when;
when["$in"] = nlohmann::json::array();
when["$in"].push_back({{"&key", {{"$cast", "string"}}}});
for (const auto& key : attachment_keys) {
when["$in"].push_back(key);
for (const auto& escaped_key : escaped_keys) {
when["$in"].push_back(escaped_key);
}
options.when = when.dump();
}
Expand Down
23 changes: 23 additions & 0 deletions tests/reduct/entry_api_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,29 @@ TEST_CASE("reduct::IBucket should remove entry attachments with numeric keys", "
REQUIRE(stored_after.empty());
}


TEST_CASE("reduct::IBucket should remove entry attachments with reserved keys", "[entry_api][1_19]") {
Fixture ctx;
auto [bucket, _] = ctx.client->CreateBucket(kBucketName);
REQUIRE(bucket);

IBucket::AttachmentMap attachments{
{"meta-1", R"({"value":1})"},
{"$system", R"({"value":"test"})"},
{"$internal", R"({"value":"hidden"})"},
};

REQUIRE(bucket->WriteAttachments("entry-1", attachments) == Error::kOk);
REQUIRE(bucket->RemoveAttachments("entry-1", std::set<std::string>{"$system", "$internal"}) == Error::kOk);

auto [stored, err] = bucket->ReadAttachments("entry-1");
REQUIRE(err == Error::kOk);
REQUIRE(stored.size() == 1);
REQUIRE(stored.contains("meta-1"));
REQUIRE(nlohmann::json::parse(stored.at("meta-1")) == nlohmann::json::parse(attachments.at("meta-1")));
}


TEST_CASE("Batch should slice data", "[batch]") {
auto batch = IBucket::Batch();

Expand Down
Loading