Merge remote-tracking branch 'internal/internal/release/2.2' into release/2.2

This commit is contained in:
Doug Bunting 2019-09-10 14:53:55 -07:00
commit de52994381
No known key found for this signature in database
GPG Key ID: EE41520987982C03
9 changed files with 104 additions and 5 deletions

View File

@ -146,6 +146,8 @@
<MicrosoftCodeAnalysisCSharpPackageVersion>2.8.0</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>2.8.0</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
<MicrosoftCSharpPackageVersion>4.5.0</MicrosoftCSharpPackageVersion>
<MicrosoftDataODataPackageVersion>5.8.4</MicrosoftDataODataPackageVersion>
<MicrosoftDataServicesClientPackageVersion>5.8.4</MicrosoftDataServicesClientPackageVersion>
<MicrosoftDiaSymReaderNativePackageVersion>1.7.0</MicrosoftDiaSymReaderNativePackageVersion>
<MicrosoftDotNetArchivePackageVersion>0.2.0-beta-63019-01</MicrosoftDotNetArchivePackageVersion>
<MicrosoftDotNetProjectModelPackageVersion>1.0.0-rc3-003121</MicrosoftDotNetProjectModelPackageVersion>

View File

@ -96,6 +96,8 @@
<ExternalDependency Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCorePackageVersion)" />
<ExternalDependency Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildUtilitiesCorePackageVersion)" />
<ExternalDependency Include="Microsoft.Internal.AspNetCore.H2Spec.All" Version="$(MicrosoftInternalAspNetCoreH2SpecAllPackageVersion)" />
<ExternalDependency Include="Microsoft.Data.OData" Version="$(MicrosoftDataODataPackageVersion)" />
<ExternalDependency Include="Microsoft.Data.Services.Client" Version="$(MicrosoftDataServicesClientPackageVersion)" />
<!-- Razor uses a custom version of roslyn packages -->
<ExternalDependency Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisCommonPackageVersion)" />

View File

@ -110,6 +110,8 @@ and are generated based on the last package release.
<LatestPackageReference Include="IdentityServer4" Version="$(IdentityServer4PackageVersion)" />
<LatestPackageReference Include="MessagePack" Version="$(MessagePackPackageVersion)" />
<LatestPackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" />
<LatestPackageReference Include="Microsoft.Data.OData" Version="$(MicrosoftDataODataPackageVersion)" />
<LatestPackageReference Include="Microsoft.Data.Services.Client" Version="$(MicrosoftDataServicesClientPackageVersion)" />
<LatestPackageReference Include="Moq" Version="$(MoqPackageVersion)" />
<!-- This version is required by MSBuild tasks or Visual Studio extensions. -->
<LatestPackageReference Include="Newtonsoft.Json" Version="9.0.1" Condition="'$(UseMSBuildJsonNet)' == 'true'" />

View File

@ -75,7 +75,9 @@ Later on, this will be checked using this condition:
</PropertyGroup>
<PropertyGroup Condition=" '$(VersionPrefix)' == '2.2.7' ">
<PackagesInPatch>
Microsoft.AspNetCore.DataProtection.AzureStorage;
Microsoft.AspNetCore.Hosting;
Microsoft.AspNetCore.SpaServices;
</PackagesInPatch>
</PropertyGroup>
</Project>

View File

@ -1,16 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Microsoft Azure Blob storrage support as key store.</Description>
<Description>Microsoft Azure Blob storage support as key store.</Description>
<TargetFramework>netstandard2.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;dataprotection;azure;blob</PackageTags>
<UseLatestPackageReferences>true</UseLatestPackageReferences>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.AspNetCore.DataProtection" />
<Reference Include="WindowsAzure.Storage" />
<Reference Include="Microsoft.Data.OData" />
</ItemGroup>
</Project>

View File

@ -9,6 +9,8 @@
<Reference Include="Microsoft.AspNetCore.DataProtection" />
<Reference Include="Microsoft.AspNetCore.DataProtection.AzureStorage" />
<Reference Include="Microsoft.Extensions.DependencyInjection" />
<Reference Include="Microsoft.Data.OData"/>
<Reference Include="Microsoft.Data.Services.Client"/>
</ItemGroup>
</Project>

View File

@ -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();
}
}
}
}

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.AspNetCore.SpaServices" />
</ItemGroup>
</Project>

View File

@ -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<string, object>
{
{ "Va<l'u\"e", "</tag>\"'}\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<JObject>(JsonConvert.SerializeObject(value));
}
}
}