Skip to content

Commit

Permalink
Mod id parse fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Jul 1, 2024
1 parent c124863 commit 833ee43
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public static bool TryParseUrl(string urlRaw, out TType articleId)
if (!url.Host.EndsWith("nexusmods.com"))
return false;

if (url.LocalPath.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) is not [_, _, var articleIdRaw, ..])
if (url.LocalPath.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) is not [_, var articles, var articleIdRaw, ..])
return false;

if (!string.Equals(articles, "articles", StringComparison.OrdinalIgnoreCase))
return false;

return TryParse(articleIdRaw, out articleId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public static bool TryParseUrl(string? urlRaw, out TType modId)
if (!url.Host.EndsWith("nexusmods.com"))
return false;

if (url.LocalPath.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) is not [_, _, var modIdRaw, ..])
if (url.LocalPath.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) is not [_, var mods, var modIdRaw, ..])
return false;

if (!string.Equals(mods, "mods", StringComparison.OrdinalIgnoreCase))
return false;

return TryParse(modIdRaw, out modId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ public static bool TryParseUrl(string urlRaw, out TType userId)
if (!url.Host.EndsWith("nexusmods.com"))
return false;

if (url.LocalPath.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) is not [_, _, var userIdRaw, ..])
if (url.LocalPath.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) is not [_, var users, var userIdRaw, ..])
return false;

if (!string.Equals(users, "users", StringComparison.OrdinalIgnoreCase))
return false;

return TryParse(userIdRaw, out userId);
}

Expand Down
6 changes: 6 additions & 0 deletions src/BUTR.Site.NexusMods.Shared/Helpers/NexusModsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public static bool TryParseModUrl(string? url, [NotNullWhen(true)] out string? g
var split = str1[1].Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if (split.Length != 3)
return false;

if (!string.Equals(split[1], "mods", StringComparison.OrdinalIgnoreCase))
return false;

if (!uint.TryParse(split[2], out var modIdNumber))
return false;
Expand Down Expand Up @@ -51,6 +54,9 @@ public static bool TryParseUserId(string? url, [NotNullWhen(true)] out string? g
if (split.Length != 3)
return false;

if (!string.Equals(split[1], "users", StringComparison.OrdinalIgnoreCase))
return false;

if (!uint.TryParse(split[2], out var userIdNumber))
return false;

Expand Down

0 comments on commit 833ee43

Please sign in to comment.