diff --git a/build/dependencies.props b/build/dependencies.props index 574bb8be33..abcfc1eac6 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -146,6 +146,8 @@ 2.8.0 2.8.0 4.5.0 + 5.8.4 + 5.8.4 1.7.0 0.2.0-beta-63019-01 1.0.0-rc3-003121 diff --git a/build/external-dependencies.props b/build/external-dependencies.props index 37b2379b42..d3398e91c4 100644 --- a/build/external-dependencies.props +++ b/build/external-dependencies.props @@ -96,6 +96,8 @@ + + diff --git a/eng/Dependencies.props b/eng/Dependencies.props index 2c0d8499f4..9ed0885937 100644 --- a/eng/Dependencies.props +++ b/eng/Dependencies.props @@ -110,6 +110,8 @@ and are generated based on the last package release. + + diff --git a/eng/PatchConfig.props b/eng/PatchConfig.props index d16cb667c1..3f12fb1a02 100644 --- a/eng/PatchConfig.props +++ b/eng/PatchConfig.props @@ -75,7 +75,9 @@ Later on, this will be checked using this condition: + Microsoft.AspNetCore.DataProtection.AzureStorage; Microsoft.AspNetCore.Hosting; + Microsoft.AspNetCore.SpaServices; diff --git a/src/DataProtection/AzureStorage/src/Microsoft.AspNetCore.DataProtection.AzureStorage.csproj b/src/DataProtection/AzureStorage/src/Microsoft.AspNetCore.DataProtection.AzureStorage.csproj index d65f55a425..2e0d4c5dc4 100644 --- a/src/DataProtection/AzureStorage/src/Microsoft.AspNetCore.DataProtection.AzureStorage.csproj +++ b/src/DataProtection/AzureStorage/src/Microsoft.AspNetCore.DataProtection.AzureStorage.csproj @@ -1,16 +1,18 @@  - Microsoft Azure Blob storrage support as key store. + Microsoft Azure Blob storage support as key store. netstandard2.0 true true aspnetcore;dataprotection;azure;blob + true + diff --git a/src/DataProtection/AzureStorage/test/Microsoft.AspNetCore.DataProtection.AzureStorage.Tests.csproj b/src/DataProtection/AzureStorage/test/Microsoft.AspNetCore.DataProtection.AzureStorage.Tests.csproj index b6926a12d2..01ac9713de 100644 --- a/src/DataProtection/AzureStorage/test/Microsoft.AspNetCore.DataProtection.AzureStorage.Tests.csproj +++ b/src/DataProtection/AzureStorage/test/Microsoft.AspNetCore.DataProtection.AzureStorage.Tests.csproj @@ -9,6 +9,8 @@ + + diff --git a/src/Middleware/SpaServices/src/Prerendering/RenderToStringResult.cs b/src/Middleware/SpaServices/src/Prerendering/RenderToStringResult.cs index 1a2e156354..0cf02247a1 100644 --- a/src/Middleware/SpaServices/src/Prerendering/RenderToStringResult.cs +++ b/src/Middleware/SpaServices/src/Prerendering/RenderToStringResult.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Text; +using System.Text.Encodings.Web; namespace Microsoft.AspNetCore.SpaServices.Prerendering { @@ -49,12 +50,16 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering foreach (var property in Globals.Properties()) { - stringBuilder.AppendFormat("window.{0} = {1};", - property.Name, - property.Value.ToString(Formatting.None)); + var propertyNameJavaScriptString = JavaScriptEncoder.Default.Encode(property.Name); + var valueJson = property.Value.ToString(Formatting.None); + var valueJsonJavaScriptString = JavaScriptEncoder.Default.Encode(valueJson); + + stringBuilder.AppendFormat("window[\"{0}\"] = JSON.parse(\"{1}\");", + propertyNameJavaScriptString, + valueJsonJavaScriptString); } return stringBuilder.ToString(); } } -} \ No newline at end of file +} diff --git a/src/Middleware/SpaServices/test/Microsoft.AspNetCore.SpaServices.Tests/Microsoft.AspNetCore.SpaServices.Tests.csproj b/src/Middleware/SpaServices/test/Microsoft.AspNetCore.SpaServices.Tests/Microsoft.AspNetCore.SpaServices.Tests.csproj new file mode 100644 index 0000000000..db1160878b --- /dev/null +++ b/src/Middleware/SpaServices/test/Microsoft.AspNetCore.SpaServices.Tests/Microsoft.AspNetCore.SpaServices.Tests.csproj @@ -0,0 +1,11 @@ + + + + netcoreapp2.0 + + + + + + + diff --git a/src/Middleware/SpaServices/test/Microsoft.AspNetCore.SpaServices.Tests/RenderToStringResultTest.cs b/src/Middleware/SpaServices/test/Microsoft.AspNetCore.SpaServices.Tests/RenderToStringResultTest.cs new file mode 100644 index 0000000000..77ce7a213c --- /dev/null +++ b/src/Middleware/SpaServices/test/Microsoft.AspNetCore.SpaServices.Tests/RenderToStringResultTest.cs @@ -0,0 +1,71 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using Microsoft.AspNetCore.SpaServices.Prerendering; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Xunit; + +namespace Microsoft.AspNetCore.SpaServices.Tests +{ + public class RenderToStringResultTest + { + [Fact] + public void HandlesNullGlobals() + { + // Arrange + var renderToStringResult = new RenderToStringResult(); + renderToStringResult.Globals = null; + + // Act + var actualScript = renderToStringResult.CreateGlobalsAssignmentScript(); + + // Assert + Assert.Equal(string.Empty, actualScript); + } + + [Fact] + public void HandlesGlobalsWithMultipleProperties() + { + // Arrange + var renderToStringResult = new RenderToStringResult(); + renderToStringResult.Globals = ToJObject(new + { + FirstProperty = "first value", + SecondProperty = new[] { "Array entry 0", "Array entry 1" } + }); + + // Act + var actualScript = renderToStringResult.CreateGlobalsAssignmentScript(); + + // Assert + var expectedScript = @"window[""FirstProperty""] = JSON.parse(""\u0022first value\u0022"");" + + @"window[""SecondProperty""] = JSON.parse(""[\u0022Array entry 0\u0022,\u0022Array entry 1\u0022]"");"; + Assert.Equal(expectedScript, actualScript); + } + + [Fact] + public void HandlesGlobalsWithCorrectStringEncoding() + { + // Arrange + var renderToStringResult = new RenderToStringResult(); + renderToStringResult.Globals = ToJObject(new Dictionary + { + { "Va\"'}\u260E" } + }); + + // Act + var actualScript = renderToStringResult.CreateGlobalsAssignmentScript(); + + // Assert + var expectedScript = @"window[""Va\u003Cl\u0027u\u0022e""] = JSON.parse(""\u0022\u003C\/tag\u003E\\\u0022\u0027}\u260E\u0022"");"; + Assert.Equal(expectedScript, actualScript); + } + + private static JObject ToJObject(object value) + { + return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(value)); + } + } +}