Skip to content

Commit

Permalink
[1.x] fix: Skip misformatted configuration files (mamba-org#3580)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
Co-authored-by: Chaoneng Quan <chaonengquan@Chaonengs-MacBook-Pro.local>
  • Loading branch information
3 people committed Nov 12, 2024
1 parent dd995ae commit 4997fab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libmamba/src/api/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,14 @@ namespace mamba
strStream << inFile.rdbuf();
std::string s = strStream.str();
config = YAML::Load(expandvars(s));
if (config.IsScalar())
{
LOG_WARNING << fmt::format(
"The configuration file at {} is misformatted or corrupted. Skipping file.",
file.string()
);
return YAML::Node();
}
}
catch (const std::exception& ex)
{
Expand Down
9 changes: 9 additions & 0 deletions libmamba/tests/src/core/test_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,15 @@ namespace mamba
env::unset("MAMBA_CHANNEL_PRIORITY");
}

TEST_CASE_FIXTURE(Configuration, "skip_misformatted_config_file")
{
std::string rc = "invalid_scalar_value";
load_test_config(rc);
CHECK_EQ(config.sources().size(), 1);
CHECK_EQ(config.valid_sources().size(), 0);
CHECK_EQ(config.dump(), "");
}

TEST_CASE_FIXTURE(Configuration, "pinned_packages")
{
std::string rc1 = unindent(R"(
Expand Down

0 comments on commit 4997fab

Please sign in to comment.