Skip to content

Commit

Permalink
Enabled sanitizing for all types of entries.
Browse files Browse the repository at this point in the history
  • Loading branch information
adya committed Apr 13, 2024
1 parent b907c9f commit 70afa0c
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions SPID/src/LookupConfigs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ namespace Distribution
}
}

std::optional<std::string> TryParse(const std::string& key, const std::string& value, const Path& path)
void TryParse(const std::string& key, const std::string& value, const Path& path)
{
auto sanitized_value = detail::sanitize(value);


try {
if (auto optData = Parse<Data,
DefaultKeyComponentParser,
Expand All @@ -66,7 +65,7 @@ namespace Distribution
LevelFiltersComponentParser,
TraitsFilterComponentParser,
IndexOrCountComponentParser,
ChanceComponentParser>(key, sanitized_value);
ChanceComponentParser>(key, value);
optData) {
auto& data = *optData;

Expand All @@ -77,11 +76,6 @@ namespace Distribution
} catch (const std::exception& e) {
logger::warn("\t\tFailed to parse entry [{} = {}]: {}", key, value, e.what());
}

if (sanitized_value != value) {
return sanitized_value;
}
return std::nullopt;
}

std::pair<bool, bool> GetConfigs()
Expand Down Expand Up @@ -118,20 +112,25 @@ namespace Distribution

for (auto& [key, entry] : *values) {
try {
if (ExclusiveGroups::INI::TryParse(key.pItem, entry, truncatedPath)) {

auto sanitized_str = detail::sanitize(entry);

if (ExclusiveGroups::INI::TryParse(key.pItem, sanitized_str, truncatedPath)) {
continue;
}

if (LinkedDistribution::INI::TryParse(key.pItem, entry, truncatedPath)) {
if (LinkedDistribution::INI::TryParse(key.pItem, sanitized_str, truncatedPath)) {
continue;
}

if (DeathDistribution::INI::TryParse(key.pItem, entry, truncatedPath)) {
if (DeathDistribution::INI::TryParse(key.pItem, sanitized_str, truncatedPath)) {
continue;
}

if (const auto sanitized_str = TryParse(key.pItem, entry, truncatedPath)) {
oldFormatMap.emplace(key, std::make_pair(entry, *sanitized_str));
TryParse(key.pItem, sanitized_str, truncatedPath);

if (sanitized_str != entry) {
oldFormatMap.emplace(key, std::make_pair(entry, sanitized_str));
}
} catch (...) {
logger::warn("\t\tFailed to parse entry [{} = {}]"sv, key.pItem, entry);
Expand Down

0 comments on commit 70afa0c

Please sign in to comment.