Dates are no file counters
"Avira AntiVir Rescue System 08-29-2011.rar", "Android Apps and Games Pack 27-02-2011", "…-cable-18-08-2012-1king.rar": counterTotal read the date as a counter (8 of 29, 2 of 2011), so the release showed a wrong file total and counted as incomplete. Dates (2011-08-29, 08-29-2011, 29.08.2011, 02-2011) are taken out before the written-out counters are read; [i/M] and (i/M) come first as before. Both implementations; tests; fixtures identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8dfccc1c8e
commit
0577b16e5e
3 files changed
+30
-2
No files matched your search
+14
-1
@@ -383,8 +383,10 @@ pub fn counter_total(subject: &str) -> Option<String> {
|
||||
let total = c.get(2).or(c.get(4)).unwrap().as_bytes();
|
||||
return Some(js_number_string(number(total)));
|
||||
}
|
||||
// Dates are no counters ("08-29-2011" read as 8 of 29).
|
||||
let undated = replace(&DATES, &s, " ", true);
|
||||
for re in [&*OF_COUNTER_OPEN, &*DASH_COUNTER, &*SLASH_COUNTER, &*ZERO_COUNTER] {
|
||||
for c in re.captures_iter(s.as_bytes()) {
|
||||
for c in re.captures_iter(undated.as_bytes()) {
|
||||
if number(&c[1]) <= number(&c[2]) {
|
||||
return Some(js_number_string(number(&c[2])));
|
||||
}
|
||||
@@ -393,6 +395,7 @@ pub fn counter_total(subject: &str) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
static DATES: LazyLock<Regex> = LazyLock::new(|| re(r"\b(?:(?:19|20)[0-9]{2}[-._ ](?:0?[1-9]|1[0-2])[-._ ][0-9]{1,2}|[0-9]{1,2}[-._ ][0-9]{1,2}[-._ ](?:19|20)[0-9]{2}|[0-9]{1,2}[-._](?:19|20)[0-9]{2})\b"));
|
||||
static COUNTERS_CAPTURE: LazyLock<Regex> = LazyLock::new(|| re(r"\[([0-9]+)/([0-9]+)\]|\(([0-9]+)/([0-9]+)\)"));
|
||||
/// The "of" counter without its closing bracket (as counterTotal's pattern).
|
||||
static OF_COUNTER_OPEN: LazyLock<Regex> = LazyLock::new(|| re(r"(?i)[\[(]?\b(?:fileSP+)?([0-9]+)SP*ofSP*([0-9]+)\b"));
|
||||
@@ -1114,6 +1117,16 @@ mod image_set_tests {
|
||||
assert!(!random_poster("w.merklein@freenet.de (muffin)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dates_are_no_counters() {
|
||||
use super::counter_total;
|
||||
assert_eq!(counter_total("Avira AntiVir Rescue System 08-29-2011.rar"), None);
|
||||
assert_eq!(counter_total("Android Apps and Games Pack 27-02-2011.rar"), None);
|
||||
assert_eq!(counter_total("Supernova-clubbin (slamfm)-cable-18-08-2012-1king.rar"), None);
|
||||
assert_eq!(counter_total(r#"Some.Album [03/12] - "x.mp3""#).as_deref(), Some("12"));
|
||||
assert_eq!(counter_total(r#"File 07390 of 19411 "x.epub""#).as_deref(), Some("19411"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn more_splits_from_the_reindex() {
|
||||
use super::random_poster;
|
||||
|
||||
Reference in new issue
Block a user