浏览代码

,RegexOptions.IgnoreCase

懒得勤快 3 年之前
父节点
当前提交
17f4e8edb8

+ 11 - 11
src/Masuit.MyBlogs.Core/Controllers/BaseController.cs

@@ -250,20 +250,20 @@ namespace Masuit.MyBlogs.Core.Controllers
                 switch (p.LimitMode)
                 {
                     case RegionLimitMode.AllowRegion:
-                        return !Regex.IsMatch(location, p.Regions);
+                        return !Regex.IsMatch(location, p.Regions, RegexOptions.IgnoreCase);
 
                     case RegionLimitMode.ForbidRegion:
-                        return Regex.IsMatch(location, p.Regions);
+                        return Regex.IsMatch(location, p.Regions, RegexOptions.IgnoreCase);
 
                     case RegionLimitMode.AllowRegionExceptForbidRegion:
-                        if (Regex.IsMatch(location, p.ExceptRegions))
+                        if (Regex.IsMatch(location, p.ExceptRegions, RegexOptions.IgnoreCase))
                         {
                             return true;
                         }
 
                         goto case RegionLimitMode.AllowRegion;
                     case RegionLimitMode.ForbidRegionExceptAllowRegion:
-                        if (Regex.IsMatch(location, p.ExceptRegions))
+                        if (Regex.IsMatch(location, p.ExceptRegions, RegexOptions.IgnoreCase))
                         {
                             return false;
                         }
@@ -305,9 +305,9 @@ namespace Masuit.MyBlogs.Core.Controllers
             }
 
             return where.And(p => p.LimitMode == null || p.LimitMode == RegionLimitMode.All ? true :
-                   p.LimitMode == RegionLimitMode.AllowRegion ? Regex.IsMatch(location, p.Regions) :
-                   p.LimitMode == RegionLimitMode.ForbidRegion ? !Regex.IsMatch(location, p.Regions) :
-                   p.LimitMode == RegionLimitMode.AllowRegionExceptForbidRegion ? Regex.IsMatch(location, p.Regions) && !Regex.IsMatch(location, p.ExceptRegions) : !Regex.IsMatch(location, p.Regions) || Regex.IsMatch(location, p.ExceptRegions));
+                   p.LimitMode == RegionLimitMode.AllowRegion ? Regex.IsMatch(location, p.Regions, RegexOptions.IgnoreCase) :
+                   p.LimitMode == RegionLimitMode.ForbidRegion ? !Regex.IsMatch(location, p.Regions, RegexOptions.IgnoreCase) :
+                   p.LimitMode == RegionLimitMode.AllowRegionExceptForbidRegion ? Regex.IsMatch(location, p.Regions, RegexOptions.IgnoreCase) && !Regex.IsMatch(location, p.ExceptRegions, RegexOptions.IgnoreCase) : !Regex.IsMatch(location, p.Regions, RegexOptions.IgnoreCase) || Regex.IsMatch(location, p.ExceptRegions, RegexOptions.IgnoreCase));
         }
 
         protected void CheckPermission(Post post)
@@ -334,7 +334,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                     break;
 
                 case RegionLimitMode.AllowRegion:
-                    if (!Regex.IsMatch(location, post.Regions))
+                    if (!Regex.IsMatch(location, post.Regions, RegexOptions.IgnoreCase))
                     {
                         Disallow(post);
                     }
@@ -342,7 +342,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                     break;
 
                 case RegionLimitMode.ForbidRegion:
-                    if (Regex.IsMatch(location, post.Regions))
+                    if (Regex.IsMatch(location, post.Regions, RegexOptions.IgnoreCase))
                     {
                         Disallow(post);
                     }
@@ -350,14 +350,14 @@ namespace Masuit.MyBlogs.Core.Controllers
                     break;
 
                 case RegionLimitMode.AllowRegionExceptForbidRegion:
-                    if (Regex.IsMatch(location, post.ExceptRegions))
+                    if (Regex.IsMatch(location, post.ExceptRegions, RegexOptions.IgnoreCase))
                     {
                         Disallow(post);
                     }
 
                     goto case RegionLimitMode.AllowRegion;
                 case RegionLimitMode.ForbidRegionExceptAllowRegion:
-                    if (Regex.IsMatch(location, post.ExceptRegions))
+                    if (Regex.IsMatch(location, post.ExceptRegions, RegexOptions.IgnoreCase))
                     {
                         break;
                     }

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/HomeController.cs

@@ -132,7 +132,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             }
 
             var where = PostBaseWhere();
-            var queryable = PostService.GetQuery(tag.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(s => Regex.Escape(s.Trim())).Aggregate(where, (current, s) => current.And(p => Regex.IsMatch(p.Label, s))));
+            var queryable = PostService.GetQuery(tag.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(s => Regex.Escape(s.Trim())).Aggregate(where, (current, s) => current.And(p => Regex.IsMatch(p.Label, s, RegexOptions.IgnoreCase))));
             var h24 = DateTime.Today.AddDays(-1);
             var posts = orderBy switch
             {

+ 4 - 3
src/Masuit.MyBlogs.Core/Controllers/PostController.cs

@@ -113,7 +113,7 @@ namespace Masuit.MyBlogs.Core.Controllers
 
             var regex = SearchEngine.LuceneIndexSearcher.CutKeywords(string.IsNullOrWhiteSpace(post.Keyword + post.Label) ? post.Title : post.Keyword + post.Label).Select(Regex.Escape).Join("|");
             ViewBag.Ads = AdsService.GetByWeightedPrice(AdvertiseType.InPage, Request.Location(), post.CategoryId, regex);
-            var related = await PostService.GetQuery(PostBaseWhere().And(p => p.Id != id && Regex.IsMatch(p.Title + (p.Keyword ?? "") + (p.Label ?? ""), regex)), p => p.AverageViewCount, false).Take(10).Select(p => new { p.Id, p.Title }).Cacheable().ToDictionaryAsync(p => p.Id, p => p.Title);
+            var related = await PostService.GetQuery(PostBaseWhere().And(p => p.Id != id && Regex.IsMatch(p.Title + (p.Keyword ?? "") + (p.Label ?? ""), regex, RegexOptions.IgnoreCase)), p => p.AverageViewCount, false).Take(10).Select(p => new { p.Id, p.Title }).Cacheable().ToDictionaryAsync(p => p.Id, p => p.Title);
             ViewBag.Related = related;
             post.ModifyDate = post.ModifyDate.ToTimeZone(HttpContext.Session.Get<string>(SessionKey.TimeZone));
             post.PostDate = post.PostDate.ToTimeZone(HttpContext.Session.Get<string>(SessionKey.TimeZone));
@@ -641,8 +641,9 @@ namespace Masuit.MyBlogs.Core.Controllers
             if (!string.IsNullOrEmpty(kw))
             {
                 kw = Regex.Escape(kw);
-                where = where.And(p => Regex.IsMatch(p.Title + p.Author + p.Email + p.Content, kw));
+                where = where.And(p => Regex.IsMatch(p.Title + p.Author + p.Email + p.Content, kw, RegexOptions.IgnoreCase));
             }
+
             var list = orderby switch
             {
                 OrderBy.Trending => await PostService.GetQuery(where).OrderByDescending(p => p.Status).ThenByDescending(p => p.IsFixedTop).ThenByDescending(p => p.PostVisitRecordStats.Sum(t => t.Count) / p.PostVisitRecordStats.Count).ToPagedListAsync<Post, PostDataModel>(page, size, MapperConfig),
@@ -1118,7 +1119,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             if (!string.IsNullOrEmpty(kw))
             {
                 kw = Regex.Escape(kw);
-                where = where.And(e => Regex.IsMatch(e.IP + e.Location + e.Referer + e.RequestUrl, kw));
+                where = where.And(e => Regex.IsMatch(e.IP + e.Location + e.Referer + e.RequestUrl, kw, RegexOptions.IgnoreCase));
             }
 
             var pages = await PostVisitRecordService.GetPagesAsync<DateTime, PostVisitRecordViewModel>(page, size, where, e => e.Time, false);

+ 10 - 5
src/Masuit.MyBlogs.Core/Controllers/SubscribeController.cs

@@ -281,7 +281,12 @@ namespace Masuit.MyBlogs.Core.Controllers
         protected Expression<Func<Post, bool>> PostBaseWhere()
         {
             var location = Request.Location() + "|" + Request.Headers[HeaderNames.Referer] + "|" + Request.Headers[HeaderNames.UserAgent];
-            return p => p.Status == Status.Published && p.LimitMode != RegionLimitMode.OnlyForSearchEngine && (p.LimitMode == null || p.LimitMode == RegionLimitMode.All ? true : p.LimitMode == RegionLimitMode.AllowRegion ? Regex.IsMatch(location, p.Regions) : p.LimitMode == RegionLimitMode.ForbidRegion ? !Regex.IsMatch(location, p.Regions) : p.LimitMode == RegionLimitMode.AllowRegionExceptForbidRegion ? Regex.IsMatch(location, p.Regions) && !Regex.IsMatch(location, p.ExceptRegions) : !Regex.IsMatch(location, p.Regions) || Regex.IsMatch(location, p.ExceptRegions));
+            return p => p.Status == Status.Published && p.LimitMode != RegionLimitMode.OnlyForSearchEngine
+                && (p.LimitMode == null || p.LimitMode == RegionLimitMode.All ? true :
+                    p.LimitMode == RegionLimitMode.AllowRegion ? Regex.IsMatch(location, p.Regions, RegexOptions.IgnoreCase) :
+                    p.LimitMode == RegionLimitMode.ForbidRegion ? !Regex.IsMatch(location, p.Regions, RegexOptions.IgnoreCase) :
+                    p.LimitMode == RegionLimitMode.AllowRegionExceptForbidRegion ? Regex.IsMatch(location, p.Regions, RegexOptions.IgnoreCase) && !Regex.IsMatch(location, p.ExceptRegions, RegexOptions.IgnoreCase) :
+                    !Regex.IsMatch(location, p.Regions, RegexOptions.IgnoreCase) || Regex.IsMatch(location, p.ExceptRegions, RegexOptions.IgnoreCase));
         }
 
         private void CheckPermission(Post post)
@@ -294,7 +299,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                     break;
 
                 case RegionLimitMode.AllowRegion:
-                    if (!Regex.IsMatch(location, post.Regions) && !Request.IsRobot())
+                    if (!Regex.IsMatch(location, post.Regions, RegexOptions.IgnoreCase) && !Request.IsRobot())
                     {
                         Disallow(post);
                     }
@@ -302,7 +307,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                     break;
 
                 case RegionLimitMode.ForbidRegion:
-                    if (Regex.IsMatch(location, post.Regions) && !Request.IsRobot())
+                    if (Regex.IsMatch(location, post.Regions, RegexOptions.IgnoreCase) && !Request.IsRobot())
                     {
                         Disallow(post);
                     }
@@ -310,14 +315,14 @@ namespace Masuit.MyBlogs.Core.Controllers
                     break;
 
                 case RegionLimitMode.AllowRegionExceptForbidRegion:
-                    if (Regex.IsMatch(location, post.ExceptRegions))
+                    if (Regex.IsMatch(location, post.ExceptRegions, RegexOptions.IgnoreCase))
                     {
                         Disallow(post);
                     }
 
                     goto case RegionLimitMode.AllowRegion;
                 case RegionLimitMode.ForbidRegionExceptAllowRegion:
-                    if (Regex.IsMatch(location, post.ExceptRegions))
+                    if (Regex.IsMatch(location, post.ExceptRegions, RegexOptions.IgnoreCase))
                     {
                         break;
                     }

+ 1 - 1
src/Masuit.MyBlogs.Core/Infrastructure/Services/AdvertisementService.cs

@@ -57,7 +57,7 @@ namespace Masuit.MyBlogs.Core.Infrastructure.Services
                 var atype = type.ToString("D");
                 Expression<Func<Advertisement, bool>> where = a => a.Types.Contains(atype) && a.Status == Status.Available;
                 var catCount = CategoryRepository.Count(_ => true);
-                where = where.And(a => a.RegionMode == RegionLimitMode.All || (a.RegionMode == RegionLimitMode.AllowRegion ? Regex.IsMatch(location, a.Regions) : !Regex.IsMatch(location, a.Regions)));
+                where = where.And(a => a.RegionMode == RegionLimitMode.All || (a.RegionMode == RegionLimitMode.AllowRegion ? Regex.IsMatch(location, a.Regions, RegexOptions.IgnoreCase) : !Regex.IsMatch(location, a.Regions, RegexOptions.IgnoreCase)));
                 if (cid.HasValue)
                 {
                     var pids = CategoryRepository.GetQuery(c => c.Id == cid).Select(c => c.ParentId + "|" + c.Parent.ParentId).Cacheable().ToArray();

+ 1 - 1
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.csproj

@@ -48,7 +48,7 @@
         <PackageReference Include="CLRStats" Version="1.0.0" />
         <PackageReference Include="Collections.Pooled" Version="1.0.82" />
         <PackageReference Include="CSRedisCore" Version="3.8.3" />
-        <PackageReference Include="EFCoreSecondLevelCacheInterceptor" Version="3.6.1" />
+        <PackageReference Include="EFCoreSecondLevelCacheInterceptor" Version="3.6.2" />
         <PackageReference Include="Hangfire" Version="1.7.30" />
         <PackageReference Include="Hangfire.MemoryStorage" Version="1.7.0" />
         <PackageReference Include="htmldiff.net-core" Version="1.3.6" />

+ 2 - 2
src/Masuit.MyBlogs.Core/Views/Post/ProtectContent.cshtml

@@ -83,11 +83,11 @@
     return;
 }
 @if(Model.ProtectContentMode==ProtectContentMode.Regions) {
-    if (Model.ProtectContentLimitMode==RegionLimitMode.AllowRegion&&Regex.IsMatch(Context.Request.Location(),Model.ProtectContentRegions)) {
+    if (Model.ProtectContentLimitMode==RegionLimitMode.AllowRegion&&Regex.IsMatch(Context.Request.Location(),Model.ProtectContentRegions, RegexOptions.IgnoreCase)) {
         @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
         return;
     }
-    if (Model.ProtectContentLimitMode==RegionLimitMode.ForbidRegion&&!Regex.IsMatch(Context.Request.Location(),Model.ProtectContentRegions)) {
+    if (Model.ProtectContentLimitMode==RegionLimitMode.ForbidRegion&&!Regex.IsMatch(Context.Request.Location(),Model.ProtectContentRegions, RegexOptions.IgnoreCase)) {
         @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
         return;
     }