diff --git a/dnf5-plugins/builddep_plugin/builddep.cpp b/dnf5-plugins/builddep_plugin/builddep.cpp index fa862d2980..54777ae16f 100644 --- a/dnf5-plugins/builddep_plugin/builddep.cpp +++ b/dnf5-plugins/builddep_plugin/builddep.cpp @@ -217,6 +217,16 @@ bool BuildDepCommand::add_from_pkg( } } +std::string escape_glob(const std::string & in) { + // Escape fnmatch glob characters in a string + std::string out = std::regex_replace(in, std::regex("\\\\"), "\\\\"); + out = std::regex_replace(out, std::regex("\\["), "\\["); + out = std::regex_replace(out, std::regex("\\]"), "\\]"); + out = std::regex_replace(out, std::regex("\\*"), "\\*"); + out = std::regex_replace(out, std::regex("\\?"), "\\?"); + return out; +} + void BuildDepCommand::run() { // get build dependencies from various inputs std::set install_specs{}; @@ -272,7 +282,8 @@ void BuildDepCommand::run() { // we do not download filelists and some files could be explicitly mentioned in provide section. The best // solution would be to merge result of provide and file search to prevent problems caused by modification // during distro lifecycle. - goal->add_rpm_install(spec, settings); + const auto & escaped_spec = escape_glob(spec); + goal->add_rpm_install(escaped_spec, settings); } }