diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index 47dbfacb45..49839828fd 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -6,6 +6,7 @@ using System.Text.RegularExpressions; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core.IO; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Core.Manifest @@ -18,7 +19,8 @@ namespace Umbraco.Core.Manifest private readonly DirectoryInfo _pluginsDir; //used to strip comments - private static readonly Regex Comments = new Regex("(/\\*.*\\*/)", RegexOptions.Compiled); + private static readonly Regex CommentsSurround = new Regex(@"/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/", RegexOptions.Compiled); + private static readonly Regex CommentsLine = new Regex(@"//.*?$", RegexOptions.Compiled | RegexOptions.Multiline); public ManifestParser(DirectoryInfo pluginsDir) { @@ -116,11 +118,20 @@ namespace Umbraco.Core.Manifest { if (m.IsNullOrWhiteSpace()) continue; - //remove any comments first, NOTE: I think JSON.Net will do this for us! but we'll leave it here for now - Comments.Replace(m, match => ""); + //remove any comments first + var replaced = CommentsSurround.Replace(m, match => " "); + replaced = CommentsLine.Replace(replaced, match => ""); - - var deserialized = JsonConvert.DeserializeObject(m); + JObject deserialized; + try + { + deserialized = JsonConvert.DeserializeObject(replaced); + } + catch (Exception ex) + { + LogHelper.Error("An error occurred parsing manifest with contents: " + m, ex); + continue; + } //validate the javascript var init = deserialized.Properties().Where(x => x.Name == "javascript").ToArray(); @@ -130,10 +141,10 @@ namespace Umbraco.Core.Manifest } //validate the css - var cssinit = deserialized.Properties().Where(x => x.Name == "stylesheet").ToArray(); + var cssinit = deserialized.Properties().Where(x => x.Name == "css").ToArray(); if (cssinit.Length > 1) { - throw new FormatException("The manifest is not formatted correctly contains more than one 'stylesheet' element"); + throw new FormatException("The manifest is not formatted correctly contains more than one 'css' element"); } //validate the property editors section @@ -146,7 +157,7 @@ namespace Umbraco.Core.Manifest var jConfig = init.Any() ? (JArray)deserialized["javascript"] : new JArray(); ReplaceVirtualPaths(jConfig); - var cssConfig = cssinit.Any() ? (JArray)deserialized["stylesheet"] : new JArray(); + var cssConfig = cssinit.Any() ? (JArray)deserialized["css"] : new JArray(); ReplaceVirtualPaths(cssConfig); //replace virtual paths for each property editor @@ -168,7 +179,7 @@ namespace Umbraco.Core.Manifest var manifest = new PackageManifest() { JavaScriptInitialize = jConfig, - StyleSheetInitialize = cssConfig, + StylesheetInitialize = cssConfig, PropertyEditors = propEditors.Any() ? (JArray)deserialized["propertyEditors"] : new JArray(), ParameterEditors = propEditors.Any() ? (JArray)deserialized["parameterEditors"] : new JArray() }; diff --git a/src/Umbraco.Core/Manifest/PackageManifest.cs b/src/Umbraco.Core/Manifest/PackageManifest.cs index 4426bb36fb..3475a60312 100644 --- a/src/Umbraco.Core/Manifest/PackageManifest.cs +++ b/src/Umbraco.Core/Manifest/PackageManifest.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.Manifest /// /// The json array used to initialize the application with the CSS dependencies required /// - public JArray StyleSheetInitialize { get; set; } + public JArray StylesheetInitialize { get; set; } /// /// The json array of property editors diff --git a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs index 7c44649c08..b51d5b84c9 100644 --- a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs @@ -12,7 +12,7 @@ namespace Umbraco.Tests.Manifest [TestFixture] public class ManifestParserTests { - + [Test] public void Parse_Property_Editors_With_Pre_Vals() { @@ -259,6 +259,46 @@ namespace Umbraco.Tests.Manifest //} + [Test] + public void Create_Manifest_With_Line_Comments() + { + var content4 = @"{ +//here's the property editors +propertyEditors: [], +//and here's the javascript +javascript: ['~/test.js', '~/test2.js']}"; + + var result = ManifestParser.CreateManifests(null, content4); + + Assert.AreEqual(1, result.Count()); + } + + [Test] + public void Create_Manifest_With_Surround_Comments() + { + var content4 = @"{ +propertyEditors: []/*we have empty property editors**/, +javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2.js']}"; + + var result = ManifestParser.CreateManifests(null, content4); + + Assert.AreEqual(1, result.Count()); + } + + [Test] + public void Create_Manifest_With_Error() + { + //NOTE: This is missing the final closing ] + var content4 = @"{ +propertyEditors: []/*we have empty property editors**/, +javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2.js' }"; + + var result = ManifestParser.CreateManifests(null, content4); + + //an error has occurred and been logged but processing continues + Assert.AreEqual(0, result.Count()); + } + [Test] public void Create_Manifest_From_File_Content() { @@ -286,9 +326,9 @@ namespace Umbraco.Tests.Manifest var result = ManifestParser.CreateManifests(null, content1, content2, content3, content4); Assert.AreEqual(4, result.Count()); - Assert.AreEqual(0, result.ElementAt(1).StyleSheetInitialize.Count); - Assert.AreEqual(2, result.ElementAt(2).StyleSheetInitialize.Count); - Assert.AreEqual(2, result.ElementAt(3).StyleSheetInitialize.Count); + Assert.AreEqual(0, result.ElementAt(1).StylesheetInitialize.Count); + Assert.AreEqual(2, result.ElementAt(2).StylesheetInitialize.Count); + Assert.AreEqual(2, result.ElementAt(3).StylesheetInitialize.Count); } diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/Package.manifest b/src/Umbraco.Web.UI/App_Plugins/MyPackage/Package.manifest index 7b4933bedf..e0243ca775 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/Package.manifest +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/Package.manifest @@ -1,5 +1,5 @@ { - propertyEditors: [ + propertyEditors: { alias: "MyPackage.Regex", name: "Regex", diff --git a/src/Umbraco.Web/UI/JavaScript/CssInitialization.cs b/src/Umbraco.Web/UI/JavaScript/CssInitialization.cs index d7b486c46f..0f197a076e 100644 --- a/src/Umbraco.Web/UI/JavaScript/CssInitialization.cs +++ b/src/Umbraco.Web/UI/JavaScript/CssInitialization.cs @@ -26,7 +26,7 @@ namespace Umbraco.Web.UI.JavaScript JArray merged = new JArray(); foreach (var m in _parser.GetManifests()) { - ManifestParser.MergeJArrays(merged, m.StyleSheetInitialize); + ManifestParser.MergeJArrays(merged, m.StylesheetInitialize); } return ParseMain(merged);