From 02b6c862d686871c65a6f794b9d722e4cefd5e96 Mon Sep 17 00:00:00 2001 From: Dario Solera Date: Wed, 17 Feb 2010 11:14:00 +0000 Subject: [PATCH] Fixed #490: not-closed snippet no longer makes the application crash. --- AssemblyVersion.cs | 4 ++-- Core/Formatter.cs | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/AssemblyVersion.cs b/AssemblyVersion.cs index e2e0896..d010c83 100644 --- a/AssemblyVersion.cs +++ b/AssemblyVersion.cs @@ -16,5 +16,5 @@ using System.Reflection; // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("3.0.2.501")] -[assembly: AssemblyFileVersion("3.0.2.501")] +[assembly: AssemblyVersion("3.0.2.502")] +[assembly: AssemblyFileVersion("3.0.2.502")] diff --git a/Core/Formatter.cs b/Core/Formatter.cs index 1039906..07701c9 100644 --- a/Core/Formatter.cs +++ b/Core/Formatter.cs @@ -48,7 +48,7 @@ namespace ScrewTurn.Wiki { private static readonly Regex HRRegex = new Regex(@"(?<=(\n|^))(\ )*----(\ )*\n", RegexOptions.Compiled); //private static readonly Regex SnippetRegex = new Regex(@"\{S(\:|\|)(.+?)(\|(.+?))*}", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); private static readonly Regex SnippetRegex = new Regex(@"\{s\:(.+?)(\|.*?)*\}", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Singleline); - private static readonly Regex ClassicSnippetVerifier = new Regex(@"\|\ ?[a-z0-9]+\ ?\=", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static readonly Regex ClassicSnippetVerifier = new Regex(@"\|\ *[\w\d]+\ *\=", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex TableRegex = new Regex(@"\{\|(\ [^\n]*)?\n.+?\|\}", RegexOptions.Compiled | RegexOptions.Singleline); private static readonly Regex IndentRegex = new Regex(@"(?<=(\n|^))\:+(\ )?.+?\n", RegexOptions.Compiled); private static readonly Regex EscRegex = new Regex(@"\(.|\n|\r)*?\<\/esc\>", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Singleline); @@ -786,10 +786,17 @@ namespace ScrewTurn.Wiki { // If the snippet is malformed this can explode balanced = ExpandToBalanceBrackets(sb, match.Index, match.Value); } - catch { - balanced = match.Value; + catch { } + + if(balanced == null) { + // Replace brackets with escaped values so that the snippets regex does not trigger anymore + sb.Replace("{", "{", match.Index, match.Length); + sb.Replace("}", "}", match.Index, match.Length); + break; // Give up + } + else { + sb.Remove(match.Index, balanced.Length); } - sb.Remove(match.Index, balanced.Length); if(balanced.IndexOf("}") == balanced.Length - 1) { // Single-level snippet @@ -808,7 +815,7 @@ namespace ScrewTurn.Wiki { lastOpen = balanced.LastIndexOf("{"); firstClosedAfterLastOpen = balanced.IndexOf("}", lastOpen + 1); - if(firstClosedAfterLastOpen <= lastOpen) break; // Give up + if(lastOpen < 0 || firstClosedAfterLastOpen <= lastOpen) break; // Give up string internalSnippet = balanced.Substring(lastOpen, firstClosedAfterLastOpen - lastOpen + 1); balanced = balanced.Remove(lastOpen, firstClosedAfterLastOpen - lastOpen + 1);