From f9263fe0d8bba8e8ae065aa4fbfab4830d823f5c Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Thu, 16 Sep 2010 20:27:28 +0000 Subject: [PATCH] Urls parsing improved --- Common/BBCodes/helpers/UrlProcessor.cs | 28 +++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/Common/BBCodes/helpers/UrlProcessor.cs b/Common/BBCodes/helpers/UrlProcessor.cs index 23d04f9..22fc013 100644 --- a/Common/BBCodes/helpers/UrlProcessor.cs +++ b/Common/BBCodes/helpers/UrlProcessor.cs @@ -22,6 +22,10 @@ namespace FLocal.Common.BBCodes { } } + private static string Safe(string str) { + return System.Web.HttpUtility.HtmlEncode(str); + } + public static HashSet KnownAliases = new HashSet { "forum.local", "forum.b.gz.ru", @@ -54,9 +58,6 @@ namespace FLocal.Common.BBCodes { } public static string ProcessLink(string link, string title, bool shortenRelative) { - if(title == null) { - title = link; - } bool isExternal = true; string url; if(shortenRelative) { @@ -67,6 +68,27 @@ namespace FLocal.Common.BBCodes { var urlInfo = new Uri(link); url = urlInfo.ToString(); } + if(title == null) { + if(!isExternal) { + var parts = url.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries); + var combinedToLower = string.Join("/", parts).ToLower(); + if(combinedToLower.StartsWith("upload/item/")) { + title = Safe(dataobjects.Upload.LoadById(int.Parse(parts[2])).filename); + } else if(combinedToLower.StartsWith("post/")) { + title = Safe(dataobjects.Post.LoadById(int.Parse(parts[1])).title); + } else if(combinedToLower.StartsWith("thread/")) { + title = Safe(dataobjects.Thread.LoadById(int.Parse(parts[1])).title); + } else if(combinedToLower.StartsWith("board/") || combinedToLower.StartsWith("boardasthread/")) { + title = Safe(dataobjects.Board.LoadById(int.Parse(parts[1])).name); + } else if(combinedToLower.StartsWith("poll/")) { + title = Safe(dataobjects.Poll.LoadById(int.Parse(parts[1])).title); + } else { + title = link; + } + } else { + title = link; + } + } string result = "" + title + ""; if(isExternal) { result += "";