From 5a15c93195bcb34b59d6e768c54f89dd0370e1ad Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 30 Sep 2013 13:55:37 +0200 Subject: [PATCH] PublishedContent - ensure exceptions don't corrupt InPreviewMode --- .../RteMacroRenderingValueConverter.cs | 32 +++++++++++-------- .../Templates/TemplateUtilities.cs | 13 +++++--- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs index fd09dbcb2d..3fb4516e3a 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs @@ -35,19 +35,25 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters UmbracoContext.Current.InPreviewMode = preview; var sb = new StringBuilder(); - var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); - MacroTagParser.ParseMacros( - source, - //callback for when text block is found - textBlock => sb.Append(textBlock), - //callback for when macro syntax is found - (macroAlias, macroAttributes) => sb.Append(umbracoHelper.RenderMacro( - macroAlias, - //needs to be explicitly casted to Dictionary - macroAttributes.ConvertTo(x => (string)x, x => x)).ToString())); - - // restore - UmbracoContext.Current.InPreviewMode = inPreviewMode; + + try + { + var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); + MacroTagParser.ParseMacros( + source, + //callback for when text block is found + textBlock => sb.Append(textBlock), + //callback for when macro syntax is found + (macroAlias, macroAttributes) => sb.Append(umbracoHelper.RenderMacro( + macroAlias, + //needs to be explicitly casted to Dictionary + macroAttributes.ConvertTo(x => (string) x, x => x)).ToString())); + } + finally + { + // restore + UmbracoContext.Current.InPreviewMode = inPreviewMode; + } return sb.ToString(); } diff --git a/src/Umbraco.Web/Templates/TemplateUtilities.cs b/src/Umbraco.Web/Templates/TemplateUtilities.cs index 9972430f21..0c4db05b23 100644 --- a/src/Umbraco.Web/Templates/TemplateUtilities.cs +++ b/src/Umbraco.Web/Templates/TemplateUtilities.cs @@ -21,10 +21,15 @@ namespace Umbraco.Web.Templates var inPreviewMode = UmbracoContext.Current.InPreviewMode; UmbracoContext.Current.InPreviewMode = preview; - text = ParseInternalLinks(text); - - // restore - UmbracoContext.Current.InPreviewMode = inPreviewMode; + try + { + text = ParseInternalLinks(text); + } + finally + { + // restore + UmbracoContext.Current.InPreviewMode = inPreviewMode; + } return text; }