diff --git a/options/configurable.cc b/options/configurable.cc index 44ad5d865d95fb240029bd2b684bafb9cf6d4495..1e85afcb96a691c41ff3136dcf951c328adb7490 100644 --- a/options/configurable.cc +++ b/options/configurable.cc @@ -747,15 +747,20 @@ Status ConfigurableHelper::GetOptionsMap( #ifndef ROCKSDB_LITE } else { status = StringToMap(value, props); - if (status.ok()) { + if (!status.ok()) { // There was an error creating the map. + *id = value; // Treat the value as id + props->clear(); // Clear the properties + status = Status::OK(); // and ignore the error + } else { auto iter = props->find(ConfigurableHelper::kIdPropName); if (iter != props->end()) { *id = iter->second; props->erase(iter); - } else if (default_id.empty()) { // Should this be an error?? - status = Status::InvalidArgument("Name property is missing"); - } else { + } else if (!default_id.empty()) { *id = default_id; + } else { // No id property and no default + *id = value; // Treat the value as id + props->clear(); // Clear the properties } } #else diff --git a/options/customizable_test.cc b/options/customizable_test.cc index 68ed84f43a5506b4a1e52575851e754171e3c88c..ee6ca4b8507c131778a27fddaae933cd7a85ca23 100644 --- a/options/customizable_test.cc +++ b/options/customizable_test.cc @@ -785,6 +785,23 @@ TEST_F(CustomizableTest, FactoryFunctionTest) { ASSERT_EQ(pointer, nullptr); } +TEST_F(CustomizableTest, URLFactoryTest) { + std::unique_ptr unique; + ConfigOptions ignore = config_options_; + ignore.ignore_unsupported_options = false; + ignore.ignore_unsupported_options = false; + ASSERT_OK(TestCustomizable::CreateFromString(ignore, "A=1;x=y", &unique)); + ASSERT_NE(unique, nullptr); + ASSERT_EQ(unique->GetId(), "A=1;x=y"); + ASSERT_OK(TestCustomizable::CreateFromString(ignore, "A;x=y", &unique)); + ASSERT_NE(unique, nullptr); + ASSERT_EQ(unique->GetId(), "A;x=y"); + unique.reset(); + ASSERT_OK(TestCustomizable::CreateFromString(ignore, "A=1?x=y", &unique)); + ASSERT_NE(unique, nullptr); + ASSERT_EQ(unique->GetId(), "A=1?x=y"); +} + TEST_F(CustomizableTest, MutableOptionsTest) { static std::unordered_map mutable_option_info = { {"mutable", diff --git a/options/options_helper.cc b/options/options_helper.cc index bf5356e75097763ce068dadfc61788941d38cdea..c11984ff9ce2c3334c06f933156d68ebb27937b5 100644 --- a/options/options_helper.cc +++ b/options/options_helper.cc @@ -644,10 +644,13 @@ Status StringToMap(const std::string& opts_str, } while (pos < opts.size()) { - size_t eq_pos = opts.find('=', pos); + size_t eq_pos = opts.find_first_of("={};", pos); if (eq_pos == std::string::npos) { return Status::InvalidArgument("Mismatched key value pair, '=' expected"); + } else if (opts[eq_pos] != '=') { + return Status::InvalidArgument("Unexpected char in key"); } + std::string key = trim(opts.substr(pos, eq_pos - pos)); if (key.empty()) { return Status::InvalidArgument("Empty key found");