1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-16 15:43:18 +08:00

Fix lax in search criteria parsing

This commit is contained in:
solstice23 2022-07-22 02:55:11 +08:00
parent 0dcb3644f5
commit ae0902ca86
No known key found for this signature in database
GPG Key ID: 7E7F5973D9260C8A

View File

@ -4,6 +4,7 @@
#nullable disable #nullable disable
using System; using System;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -312,34 +313,50 @@ namespace osu.Game.Screens.Select
private static bool tryUpdateLengthRange(FilterCriteria criteria, Operator op, string val) private static bool tryUpdateLengthRange(FilterCriteria criteria, Operator op, string val)
{ {
if (val.Contains(':')) List<string> parts = new List<string>();
if (Regex.IsMatch(val, @"^\d+(:\d+(:\d+)?)?$")) // formats like 12:34
{ {
if (val.Contains('h') || val.Contains('m') || val.Contains('s')) string[] splited = val.Split(':');
for (int i = splited.Length - 1; i >= 0; i--)
parts.Add(splited[i] + "smh"[splited.Length - i - 1]);
}
else if (Regex.IsMatch(val, @"^(\d+(\.\d+)?[hms]){1,3}$")) // formats like 1h2m3s
{
if (!"hms".Contains(Regex.Replace(val, @"[\d\.]", "")))
return false; return false;
int count = val.Count(c => c == ':'); string[] splited = Regex.Split(val, @"(?<=[hms])").Where(x => x.Length > 0).ToArray();
if (count > 3) for (int i = splited.Length - 1; i >= 0; i--)
return false; parts.Add(splited[i]);
}
if (count > 2) else if (Regex.IsMatch(val, @"^\d+(\.\d+)?$")) // only one number
val = val.Replace(':', 'h'); {
parts.Add(val + 's');
val = val.Replace(':', 'm');
} }
string[] parts = Regex.Split(val, @"(?<=[msh])").Where(x => x.Length > 0).ToArray(); if (parts.Count == 0)
double totalLength = 0; return false;
int minScale = 1000;
foreach (string part in parts) double totalLength = 0;
int minScale = 3600000;
for (int i = 0; i < parts.Count; i++)
{ {
if (!tryParseDoubleWithPoint(part.TrimEnd('m', 's', 'h'), out double length)) string part = parts[i];
string partNoUnit = part.TrimEnd('m', 's', 'h');
if (!tryParseDoubleWithPoint(partNoUnit, out double length))
return false; return false;
if (i != parts.Count - 1 && length >= 60)
return false;
if (i != 0 && partNoUnit.Contains('.'))
return false;
int scale = getLengthScale(part); int scale = getLengthScale(part);
totalLength += length * scale; totalLength += length * scale;
minScale = Math.Min(minScale, scale); minScale = Math.Min(minScale, scale);
} }
return tryUpdateCriteriaRange(ref criteria.Length, op, totalLength, minScale / 2.0); return tryUpdateCriteriaRange(ref criteria.Length, op, totalLength, minScale / 2.0);
} }
} }