Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix slow regular expressions when parens / single quotes are present

  • Loading branch information...
commit c7d4c09cc147de6f11ea7950baa1bc19b2724a1b 1 parent 86c711f
Timo Dörr authored
Showing with 8 additions and 2 deletions.
  1. +8 −2 MarkdownSharp/Markdown.cs
10 MarkdownSharp/Markdown.cs
View
@@ -933,7 +933,10 @@ private string AnchorInlineEvaluator(Match match)
string linkText = match.Groups[2].Value;
string tmpurl = match.Groups[3].Value;
string title = Regex.Match (tmpurl,"[^\"]*\"(.*)\"[^\"]*").Groups[1].Value;
- string url = new Regex("(?<=\")(.*)*(?=\")").Replace (tmpurl, "").Replace (@" """"","");
+
+ // this regex is too slow
+ //string url = new Regex("(?<=\")(.*)*(?=\")").Replace (tmpurl, "").Replace (@" """"","");
+ string url = tmpurl.Split ('"').First ().Trim ();
string result;
url = EncodeProblemUrlChars(url);
@@ -1052,7 +1055,10 @@ private string ImageInlineEvaluator(Match match)
string alt = match.Groups[2].Value;
string tmpurl = match.Groups[3].Value;
string title = Regex.Match (tmpurl,"[^\"]*\"(.*)\"[^\"]*").Groups[1].Value;
- string url = new Regex("(?<=\")(.*)*(?=\")").Replace (tmpurl, "").Replace (@" """"","");
+ // for some reason this regex is very slow
+ // also due to a bug with parens, if only one " is given, url extraction will fail
+ //string url = new Regex("(?<=\")(.*)*(?=\")").Replace (tmpurl, "").Replace (@" """"","");
+ string url = tmpurl.Split ('"').First ().Trim ();
string result;
Please sign in to comment.
Something went wrong with that request. Please try again.