Skip to content

Commit 1427967

Browse files
authored
Merge pull request #1849 from johnhenley/dev97/issues/regex-1845
TASK: Update Regex objects to use DNN cached regex objects
2 parents 3ec2f21 + 6175ebd commit 1427967

6 files changed

Lines changed: 54 additions & 73 deletions

File tree

Dnn.CommunityForums/CustomControls/ServerControls/Callback.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public string XSSFilter(string sText)
368368
{
369369
sText = System.Net.WebUtility.UrlDecode(sText);
370370
string pattern = "<script.*/*>|</script>|<[a-zA-Z][^>]*=['\"]+javascript:\\w+.*['\"]+>|<\\w+[^>]*\\son\\w+=.*[ /]*>";
371-
return RegexUtils.GetCachedRegex(pattern, RegexOptions.Compiled & RegexOptions.IgnoreCase, 2).Replace(sText, string.Empty).Replace("-->", string.Empty).Replace("<!--", string.Empty);
371+
return DotNetNuke.Common.Utilities.RegexUtils.GetCachedRegex(pattern, RegexOptions.Compiled & RegexOptions.IgnoreCase, 2).Replace(sText, string.Empty).Replace("-->", string.Empty).Replace("<!--", string.Empty);
372372
}
373373

374374
protected override void CreateChildControls()

Dnn.CommunityForums/CustomControls/UserControls/WhatsNewRSS.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,7 @@ private string BuildRSS()
330330
{
331331
var strHost = Common.Globals.AddHTTP(Common.Globals.GetDomainName(HttpContext.Current.Request)) + "/";
332332
const string pattern = "(&#91;IMAGE:(.+?)&#93;)";
333-
var regExp = new Regex(pattern);
334-
var matches = regExp.Matches(bodyHtml);
335-
foreach (Match match in matches)
333+
foreach (Match match in DotNetNuke.Common.Utilities.RegexUtils.GetCachedRegex(pattern).Matches(bodyHtml))
336334
{
337335
var sImage = "<img src=\"" + strHost + "DesktopModules/ActiveForums/viewer.aspx?portalid=" + this.PortalId + "&moduleid=" + this.ModuleId + "&attachid=" + match.Groups[2].Value + "\" border=\"0\" />";
338336
bodyHtml = bodyHtml.Replace(match.Value, sImage);
@@ -344,9 +342,7 @@ private string BuildRSS()
344342
{
345343
var strHost = Common.Globals.AddHTTP(Common.Globals.GetDomainName(HttpContext.Current.Request)) + "/";
346344
const string pattern = "(&#91;THUMBNAIL:(.+?)&#93;)";
347-
var regExp = new Regex(pattern);
348-
var matches = regExp.Matches(bodyHtml);
349-
foreach (Match match in matches)
345+
foreach (Match match in DotNetNuke.Common.Utilities.RegexUtils.GetCachedRegex(pattern).Matches(bodyHtml))
350346
{
351347
var thumbId = match.Groups[2].Value.Split(':')[0];
352348
var parentId = match.Groups[2].Value.Split(':')[1];

Dnn.CommunityForums/class/TemplateUtils.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public static string ParseRoles(string template, string userRoles)
393393

394394
const string pattern = @"\[ROLES:(.+?)\]";
395395

396-
template = Regex.Replace(template, pattern, delegate (Match match)
396+
template = DotNetNuke.Common.Utilities.RegexUtils.GetCachedRegex(pattern).Replace(template, match =>
397397
{
398398
if (userRoleArray == null || userRoleArray.Count == 0)
399399
{
@@ -464,7 +464,7 @@ internal static string ParseProfile(DotNetNuke.Modules.ActiveForums.Entities.For
464464
var s = template ?? string.Empty;
465465
const string pattern = "(\\[DNN:PROFILE:(.+?)\\])";
466466

467-
foreach (Match match in Regex.Matches(s, pattern))
467+
foreach (Match match in DotNetNuke.Common.Utilities.RegexUtils.GetCachedRegex(pattern).Matches(s))
468468
{
469469
var sReplace = string.Empty;
470470
var sResource = string.Empty;
@@ -565,7 +565,7 @@ private static string ParsePreview(int portalId, string template, string message
565565
{
566566
var strHost = Common.Globals.AddHTTP(Common.Globals.GetDomainName(HttpContext.Current.Request)) + "/";
567567
const string pattern = "(&#91;IMAGE:(.+?)&#93;)";
568-
foreach (Match match in Regex.Matches(message, pattern))
568+
foreach (Match match in DotNetNuke.Common.Utilities.RegexUtils.GetCachedRegex(pattern).Matches(message))
569569
{
570570
var sImage = string.Format("<img src=\"{0}DesktopModules/ActiveForums/viewer.aspx?portalid={1}&moduleid={2}&attachid={3}\" border=\"0\" />", strHost, portalId, moduleId, match.Groups[2].Value);
571571
message = message.Replace(match.Value, sImage);
@@ -577,7 +577,7 @@ private static string ParsePreview(int portalId, string template, string message
577577
{
578578
var strHost = string.Concat(Common.Globals.AddHTTP(Common.Globals.GetDomainName(HttpContext.Current.Request)), "/");
579579
const string pattern = "(&#91;THUMBNAIL:(.+?)&#93;)";
580-
foreach (Match match in Regex.Matches(message, pattern))
580+
foreach (Match match in DotNetNuke.Common.Utilities.RegexUtils.GetCachedRegex(pattern).Matches(message))
581581
{
582582
var thumbId = match.Groups[2].Value.Split(':')[0];
583583
var parentId = match.Groups[2].Value.Split(':')[1];
@@ -587,16 +587,9 @@ private static string ParsePreview(int portalId, string template, string message
587587
}
588588

589589
template = template.Replace("[BODY]", message);
590-
if (Regex.IsMatch(template, "<CODE([^>]*)>", RegexOptions.IgnoreCase))
590+
if (DotNetNuke.Common.Utilities.RegexUtils.GetCachedRegex("<CODE([^>]*)>", RegexOptions.IgnoreCase).IsMatch(template))
591591
{
592-
if (Regex.IsMatch(message, "<CODE([^>]*)>", RegexOptions.IgnoreCase))
593-
{
594-
foreach (Match m in Regex.Matches(message, "<CODE([^>]*)>(.*?)</CODE>", RegexOptions.IgnoreCase))
595-
{
596-
message = message.Replace(m.Value, m.Value.Replace("<br>", System.Environment.NewLine));
597-
}
598-
}
599-
592+
template = CodeParser.ReplaceBreakTagsWithNewLines(template);
600593
template = CodeParser.ParseCode(System.Net.WebUtility.HtmlDecode(template));
601594
}
602595

0 commit comments

Comments
 (0)