今天在使用BlogEngine最新版(1.4.5)的过程中,突然发现一个日志分类的重要Bug,严重影响使用。

  具体表现:从首页打开子分类(所有非根级分类)的页面通通报404错误。

  简单检查,发现BlogEngine在UrlRewrite及通用函数类(Utils)中存在由于字符过滤不严格造成的URL问题。一个简单的修复方法如下:

  1、打开BlogEngine.Core工程下的Utils.cs文件,找到两个静态函数【34行】RemoveIllegalCharacters()和【58行】RemoveExtraHyphen(),如下:

 
  1. public static string RemoveIllegalCharacters(string text)   
  2. {   
  3.     if (string.IsNullOrEmpty(text))   
  4. return text;   
  5.   
  6.     text = text.Replace(":"string.Empty);   
  7.     text = text.Replace("/"string.Empty);   
  8.     text = text.Replace("?"string.Empty);   
  9.     text = text.Replace("#"string.Empty);   
  10.     text = text.Replace("["string.Empty);   
  11.     text = text.Replace("]"string.Empty);   
  12.     text = text.Replace("@"string.Empty);   
  13.     text = text.Replace("."string.Empty);   
  14.     text = text.Replace(","string.Empty);   
  15.     text = text.Replace("\""string.Empty);   
  16.     text = text.Replace("&"string.Empty);   
  17.     text = text.Replace("'"string.Empty);   
  18.     text = text.Replace(" ""-");   
  19.     text = RemoveDiacritics(text);   
  20.     text = RemoveExtraHyphen(text);   
  21.   
  22.     return HttpUtility.UrlEncode(text).Replace("%"string.Empty);   
  23. }   
  24.   
  25. private static string RemoveExtraHyphen(string text)   
  26. {   
  27.     if (text.Contains("--"))   
  28.     {   
  29.         text = text.Replace("--""-");   
  30.         return RemoveExtraHyphen(text);   
  31.     }   
  32.   
  33.     return text;   
  34. }  

  2、修改如下:

 
  1. public static string RemoveIllegalCharacters(string text)   
  2. {   
  3.     if (string.IsNullOrEmpty(text))   
  4. return text;   
  5.   
  6.     text = text.Replace(":"string.Empty);   
  7.     text = text.Replace("/"string.Empty);   
  8.     text = text.Replace("?"string.Empty);   
  9.     text = text.Replace("#"string.Empty);   
  10.     text = text.Replace("["string.Empty);   
  11.     text = text.Replace("]"string.Empty);   
  12.     text = text.Replace("@"string.Empty);   
  13.     text = text.Replace("."string.Empty);   
  14.     text = text.Replace(","string.Empty);   
  15.     text = text.Replace("\""string.Empty);   
  16.     text = text.Replace("&"string.Empty);   
  17.     text = text.Replace("'"string.Empty);   
  18.     text = text.Replace(" ""-");   
  19.     text = RemoveDiacritics(text);   
  20.     text = RemoveExtraHyphen(text);   
  21.   
  22.     return HttpUtility.UrlEncode(text).Replace("%7c""/").Replace("%"string.Empty);   
  23. }   
  24.   
  25. private static string RemoveExtraHyphen(string text)   
  26. {   
  27.     if (text.Contains("---"))   
  28.     {   
  29.         text = text.Replace("---""|");   
  30.         return RemoveExtraHyphen(text);   
  31.     }   
  32.     else if (text.Contains("--"))   
  33.     {   
  34.         text = text.Replace("--""-");   
  35.         return RemoveExtraHyphen(text);   
  36.     }   
  37.   
  38.     return text;   
  39. }  

  3、修改好后,重新编译BlogEngine.Core后,把所得BlogEngine.Core.dll替换一下原来的即可,呵呵。

Currently rated 3.2 by 11 people

  • Currently 3.181818/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5