|
|
@ -3,23 +3,26 @@ using Flurl.Http;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Recyclarr.TrashLib.Http;
|
|
|
|
namespace Recyclarr.TrashLib.Http;
|
|
|
|
|
|
|
|
|
|
|
|
public static class FlurlExtensions
|
|
|
|
public static partial class FlurlExtensions
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public static string SanitizedExceptionMessage(this FlurlHttpException exception)
|
|
|
|
public static string SanitizedExceptionMessage(this FlurlHttpException exception)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Replace full URLs
|
|
|
|
// Replace full URLs
|
|
|
|
const string urlExpression =
|
|
|
|
var result = UrlRegex().Replace(exception.Message, Sanitize);
|
|
|
|
@"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}(\:[0-9]+)?\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)";
|
|
|
|
|
|
|
|
var result = Regex.Replace(exception.Message, urlExpression, Sanitize);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// There are sometimes parenthetical parts of the message that contain the host but are not
|
|
|
|
// There are sometimes parenthetical parts of the message that contain the host but are not
|
|
|
|
// detected as true URLs. Just strip those out completely.
|
|
|
|
// detected as true URLs. Just strip those out completely.
|
|
|
|
const string hostExpression = @"\([-a-zA-Z0-9@:%._+~#=]{1,256}(?:\:[0-9]+)\)";
|
|
|
|
return HostRegex().Replace(result, "");
|
|
|
|
return Regex.Replace(result, hostExpression, "");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static string Sanitize(Match match)
|
|
|
|
private static string Sanitize(Match match)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return FlurlLogging.SanitizeUrl(match.Value).ToString();
|
|
|
|
return FlurlLogging.SanitizeUrl(match.Value).ToString() ?? match.Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[GeneratedRegex(@"\([-a-zA-Z0-9@:%._+~#=]{1,256}(?::[0-9]+)?\)")]
|
|
|
|
|
|
|
|
private static partial Regex HostRegex();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[GeneratedRegex(@"https?://(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}(:[0-9]+)?\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)")]
|
|
|
|
|
|
|
|
private static partial Regex UrlRegex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|