From 9cd1bc827cfddc05fb0cda37c6d209ffc800c87a Mon Sep 17 00:00:00 2001 From: Jaroslav Rohel Date: Tue, 3 Sep 2024 11:52:23 +0200 Subject: [PATCH] config-manager: Fix addrepo from-repofile with empty/comment lines Comments and empty lines were interpreted as options in the configuration file validity test. Now they are ignored. --- dnf5-plugins/config-manager_plugin/addrepo.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dnf5-plugins/config-manager_plugin/addrepo.cpp b/dnf5-plugins/config-manager_plugin/addrepo.cpp index 3e2eb0704..75673fa3c 100644 --- a/dnf5-plugins/config-manager_plugin/addrepo.cpp +++ b/dnf5-plugins/config-manager_plugin/addrepo.cpp @@ -346,6 +346,12 @@ void ConfigManagerAddRepoCommand::add_repos_from_repofile( // Test if the repository options can be set. for (const auto & [repo_id, repo_opts] : parser.get_data()) { for (const auto & [key, key_val] : repo_opts) { + // Skip empty lines and comment lines (ConfigParser stores the empty line and comment line + // in an automatically generated key whose name starts with the '#' character). + if (key.starts_with('#')) { + continue; + } + try { tmp_repo_conf.opt_binds().at(key).new_string(Option::Priority::RUNTIME, key_val); } catch (const Error & ex) {