From 8bd91743708dbdf6d0996b0d631520ac97d39c28 Mon Sep 17 00:00:00 2001 From: Evgeny S Date: Sat, 3 Jun 2017 19:55:30 +0300 Subject: [PATCH] Update metadata.rs Properly check forbidden and allowed lists, skip tracks where allowed list is set but is empty. --- src/metadata.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/metadata.rs b/src/metadata.rs index c1d51737..03877af7 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -17,18 +17,29 @@ fn parse_restrictions<'s, I>(restrictions: I, country: &str, catalogue: &str) -> where I: IntoIterator { let mut forbidden = "".to_string(); + let mut has_forbidden = false; + let mut allowed = "".to_string(); + let mut has_allowed = false; + let rs = restrictions.into_iter().filter(|r| r.get_catalogue_str().contains(&catalogue.to_owned()) ); for r in rs { - forbidden.push_str(r.get_countries_forbidden()); - allowed.push_str(r.get_countries_allowed()); + if r.has_countries_forbidden() { + forbidden.push_str(r.get_countries_forbidden()); + has_forbidden = true; + } + + if r.has_countries_allowed() { + allowed.push_str(r.get_countries_allowed()); + has_allowed = true; + } } - (forbidden == "" || !countrylist_contains(forbidden.as_str(), country)) && - (allowed == "" || countrylist_contains(allowed.as_str(), country)) + (!has_forbidden || !countrylist_contains(forbidden.as_str(), country)) && + (!has_allowed || countrylist_contains(allowed.as_str(), country)) } pub trait MetadataTrait : Send + 'static {