make sure the keyword is really empty (does not contain separators only)

This commit is contained in:
yggverse 2025-08-12 00:58:40 +03:00
parent e2e7ceda9d
commit 50bdb438b5

View file

@ -103,6 +103,10 @@ impl Public {
keyword: Option<&str>, keyword: Option<&str>,
sort_order: Option<(Sort, Order)>, sort_order: Option<(Sort, Order)>,
) -> Result<Vec<File>, Error> { ) -> Result<Vec<File>, Error> {
const S: &[char] = &[
'_', '-', ':', ';', ',', '(', ')', '[', ']', '/', '!', '?',
' ', // @TODO make separators list optional
];
let mut files = Vec::with_capacity(self.default_capacity); let mut files = Vec::with_capacity(self.default_capacity);
for dir_entry in fs::read_dir(&self.root)? { for dir_entry in fs::read_dir(&self.root)? {
let entry = dir_entry?; let entry = dir_entry?;
@ -111,13 +115,10 @@ impl Public {
continue; continue;
} }
if let Some(k) = keyword if let Some(k) = keyword
&& !k.is_empty() && !k.trim_matches(S).is_empty()
&& !librqbit_core::torrent_metainfo::torrent_from_bytes(&fs::read(&path)?) && !librqbit_core::torrent_metainfo::torrent_from_bytes(&fs::read(&path)?)
.is_ok_and(|m: librqbit_core::torrent_metainfo::TorrentMetaV1Owned| { .is_ok_and(|m: librqbit_core::torrent_metainfo::TorrentMetaV1Owned| {
k.split([ k.split(S)
'_', '-', ':', ';', ',', '(', ')', '[', ']', '/', '!', '?',
' ', // @TODO make separators list optional
])
.filter(|s| !s.is_empty()) .filter(|s| !s.is_empty())
.map(|s| s.trim().to_lowercase()) .map(|s| s.trim().to_lowercase())
.all(|q| { .all(|q| {