From ab05f1b4e2f5011fd871c6225e79dc4edad30980 Mon Sep 17 00:00:00 2001 From: Diego Heras Date: Sun, 31 Jul 2022 03:11:39 +0200 Subject: [PATCH] core: fix errors removing old cookies (#13425) --- src/Jackett.Common/Utils/CookieUtil.cs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Jackett.Common/Utils/CookieUtil.cs b/src/Jackett.Common/Utils/CookieUtil.cs index 3bb8a4b86..42a063130 100644 --- a/src/Jackett.Common/Utils/CookieUtil.cs +++ b/src/Jackett.Common/Utils/CookieUtil.cs @@ -5,14 +5,11 @@ using System.Linq; using System.Net; using System.Reflection; using System.Text.RegularExpressions; -using NLog; namespace Jackett.Common.Utils { public static class CookieUtil { - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie // NOTE: we are not checking non-ascii characters and we should private static readonly Regex _CookieRegex = new Regex(@"([^\(\)<>@,;:\\""/\[\]\?=\{\}\s]+)=([^,;\\""\s]+)"); @@ -55,17 +52,15 @@ namespace Jackett.Common.Utils .InvokeMember("m_domainTable", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null, cookieJar, new object[] { }); foreach (var key in table.Keys) - try - { - foreach (Cookie cookie in cookieJar.GetCookies(new Uri($"http://{key}"))) - cookie.Expired = true; - foreach (Cookie cookie in cookieJar.GetCookies(new Uri($"https://{key}"))) - cookie.Expired = true; - } - catch (Exception) - { - logger.Warn("Unable to delete the cookies of domain: " + key); - } + { + var domain = (string)key; + if (domain.StartsWith(".")) + domain = domain.Substring(1); + foreach (Cookie cookie in cookieJar.GetCookies(new Uri($"http://{domain}"))) + cookie.Expired = true; + foreach (Cookie cookie in cookieJar.GetCookies(new Uri($"https://{domain}"))) + cookie.Expired = true; + } } }