Skip to content

Commit

Permalink
Refuse regex for anything but searchby name and name-desc
Browse files Browse the repository at this point in the history
It's perfectly valid for a package to provide something like libfoo.so,
but the AUR doesn't allow substring matching outside of name and
name-desc, so our fragment-finding logic would happily chop libfoo.so
into libfoo, and never return anything.
  • Loading branch information
falconindy committed Aug 20, 2024
1 parent 3889e6f commit 7c814e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/auracle/auracle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,20 @@ int Auracle::Search(const std::vector<std::string>& args,
});
};

// 'name' and 'name-desc' are the only dimensions where the AUR allows
// substring matching, so that's the only case where we're able to provide
// something resembling regex support.
const bool allow_regex =
options.allow_regex &&
(options.search_by == aur::SearchRequest::SearchBy::NAME ||
options.search_by == aur::SearchRequest::SearchBy::NAME_DESC);

std::vector<aur::Package> packages;
for (const auto& arg : args) {
std::string_view frag = arg;
if (options.allow_regex) {
if (allow_regex) {
frag = GetSearchFragment(arg);
if (frag.empty() && options.allow_regex) {
if (frag.empty()) {
std::cerr << "error: search string '" << arg
<< "' insufficient for searching by regular expression.\n";
return -EINVAL;
Expand Down
12 changes: 12 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ def testSearchByDimensions(self):
'name',
'name-desc',
'maintainer',
'comaintainers',
'depends',
'makedepends',
'optdepends',
'checkdepends',
'provides',
'replaces',
'conflicts',
]

for dim in dimensions:
Expand All @@ -34,6 +38,14 @@ def testSearchByDimensions(self):
self.assertEqual(1, len(r.requests_sent))
self.assertIn(f'by={dim}', r.requests_sent[0].path)

for dim in dimensions[2:]:
r = self.Auracle(['search', '--searchby', dim, 'libfoo.so'])
self.assertEqual(0, r.process.returncode)

self.assertEqual(1, len(r.requests_sent))
self.assertIn('/libfoo.so', r.requests_sent[0].path)
self.assertIn(f'by={dim}', r.requests_sent[0].path)

def testSearchByInvalidDimension(self):
r = self.Auracle(['search', '--searchby=notvalid', 'somesearchterm'])
self.assertNotEqual(0, r.process.returncode)
Expand Down

0 comments on commit 7c814e3

Please sign in to comment.