Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builddep: Escape glob characters in pkg specs #1088

Conversation

evan-goode
Copy link
Member

Not parsing the pkg specs as globs would require an ABI-breaking change (#1085). A workaround that doesn't involve breaking changes is to escape the glob characters in the pkg specs.

Related: rpm-software-management/mock#1267
Resolves #1084

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("\\?"), "\\?");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such strings are going to stay in the "glob pattern" category because of the simple check. Is that OK for is_glob_pattern callers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume yes... just that DNF5/libdnf goes through more expensive code paths... but long-term, #1085 looks like semantically more correct. Perhaps "the" issue is about to be fixed in two phases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the code path is a bit more expensive, but anyway I think the escaped strings need to be handled as globs or else the escaping backslashes (\[, etc) will be treated as literal and not as escaping the following glob character.

#1085 is definitely the better fix in the long term, but I think both patches are small and tidy enough that we can do this for now, and possibly revert it in favor of #1085 later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular expressions seem to be a bit of overkill here. How about doing the escaping in a single loop?

  std::string out;
  for (const auto ch : str) {
    if (ch == '*' || ch == '?' || ch == '[' || ch == ']') {
      out += '\\';
    }
    out += ch;
  }
  return out;

But I'm not blocking the merge on it if you prefer regex.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, that's saner and I think still plenty readable.

dnf5-plugins/builddep_plugin/builddep.cpp Show resolved Hide resolved
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("\\?"), "\\?");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular expressions seem to be a bit of overkill here. How about doing the escaping in a single loop?

  std::string out;
  for (const auto ch : str) {
    if (ch == '*' || ch == '?' || ch == '[' || ch == ']') {
      out += '\\';
    }
    out += ch;
  }
  return out;

But I'm not blocking the merge on it if you prefer regex.

Not parsing the pkg specs as globs would require an ABI-breaking change
(rpm-software-management#1085). A
workaround that doesn't involve breaking changes is to escape the glob
characters in the pkg specs.

Related: rpm-software-management/mock#1267
Resolves rpm-software-management#1084
@evan-goode evan-goode force-pushed the evan-goode/builddep-escape-glob branch from 2b7da7b to 78a462f Compare December 13, 2023 18:45
Copy link
Member

@m-blaha m-blaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@m-blaha m-blaha added this pull request to the merge queue Dec 14, 2023
Merged via the queue into rpm-software-management:main with commit a4662a7 Dec 14, 2023
5 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

builddep cannot handle python3dist(build[virtualenv])
3 participants