From 3bf521d5caadb395bd26e0df82d8d8d3de78b599 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 15 Mar 2019 20:32:03 +0100 Subject: [PATCH] song/TagSongFilter: apply negation properly to multiple tag values The old implementation didn't make a lot of sense; the "!=" operator was not actually the opposite of "==". Closes https://github.com/MusicPlayerDaemon/MPD/issues/505 --- NEWS | 1 + src/song/TagSongFilter.cxx | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index af3e6e142..41f9169a9 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ ver 0.21.6 (not yet released) * protocol - allow loading playlists specified as absolute filesystem paths + - fix negated filter expressions with multiple tag values - fix "list" with filter expression * input - cdio_paranoia: fix build failure due to missing #include diff --git a/src/song/TagSongFilter.cxx b/src/song/TagSongFilter.cxx index df92ed435..00f2021aa 100644 --- a/src/song/TagSongFilter.cxx +++ b/src/song/TagSongFilter.cxx @@ -43,8 +43,8 @@ TagSongFilter::Match(const Tag &tag) const noexcept visited_types[i.type] = true; if ((type == TAG_NUM_OF_ITEM_TYPES || i.type == type) && - filter.Match(i.value)) - return true; + filter.MatchWithoutNegation(i.value)) + return !filter.IsNegated(); } if (type < TAG_NUM_OF_ITEM_TYPES && !visited_types[type]) { @@ -61,7 +61,7 @@ TagSongFilter::Match(const Tag &tag) const noexcept for (const auto &item : tag) { if (item.type == tag2 && - filter.Match(item.value)) { + filter.MatchWithoutNegation(item.value)) { result = true; break; } @@ -69,7 +69,7 @@ TagSongFilter::Match(const Tag &tag) const noexcept return true; })) - return result; + return result != filter.IsNegated(); /* If the search critieron was not visited during the sweep through the song's tag, it means this field @@ -78,10 +78,10 @@ TagSongFilter::Match(const Tag &tag) const noexcept then it's a match as well and we should return true. */ if (filter.empty()) - return true; + return !filter.IsNegated(); } - return false; + return filter.IsNegated(); } bool