Merge branch 'release/2.2'

This commit is contained in:
Ryan Nowak 2018-10-08 16:32:01 -07:00
commit d37052c467
6 changed files with 167 additions and 18 deletions

View File

@ -47,8 +47,8 @@
<MicrosoftAspNetCoreRazorTagHelpersTestingSourcesPackageVersion>3.0.0-alpha1-10549</MicrosoftAspNetCoreRazorTagHelpersTestingSourcesPackageVersion>
<MicrosoftAspNetCoreResponseCachingAbstractionsPackageVersion>3.0.0-alpha1-10549</MicrosoftAspNetCoreResponseCachingAbstractionsPackageVersion>
<MicrosoftAspNetCoreResponseCachingPackageVersion>3.0.0-alpha1-10549</MicrosoftAspNetCoreResponseCachingPackageVersion>
<MicrosoftAspNetCoreRoutingAbstractionsPackageVersion>3.0.0-a-alpha1-matcher-policy-master-17054</MicrosoftAspNetCoreRoutingAbstractionsPackageVersion>
<MicrosoftAspNetCoreRoutingPackageVersion>3.0.0-a-alpha1-matcher-policy-master-17054</MicrosoftAspNetCoreRoutingPackageVersion>
<MicrosoftAspNetCoreRoutingAbstractionsPackageVersion>3.0.0-a-alpha1-address-scheme-17061</MicrosoftAspNetCoreRoutingAbstractionsPackageVersion>
<MicrosoftAspNetCoreRoutingPackageVersion>3.0.0-a-alpha1-address-scheme-17061</MicrosoftAspNetCoreRoutingPackageVersion>
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>3.0.0-alpha1-10549</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
<MicrosoftAspNetCoreServerKestrelPackageVersion>3.0.0-alpha1-10549</MicrosoftAspNetCoreServerKestrelPackageVersion>
<MicrosoftAspNetCoreSessionPackageVersion>3.0.0-alpha1-10549</MicrosoftAspNetCoreSessionPackageVersion>

View File

@ -1,6 +1,7 @@
// 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 Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Routing;
namespace Microsoft.AspNetCore.Mvc
@ -19,10 +20,18 @@ namespace Microsoft.AspNetCore.Mvc
/// Generates a URL with an absolute path for an action method, which contains the action
/// name, controller name, route values, protocol to use, host name, and fragment specified by
/// <see cref="UrlActionContext"/>. Generates an absolute URL if <see cref="UrlActionContext.Protocol"/> and
/// <see cref="UrlActionContext.Host"/> are non-<c>null</c>.
/// <see cref="UrlActionContext.Host"/> are non-<c>null</c>. See the remarks section for important security information.
/// </summary>
/// <param name="actionContext">The context object for the generated URLs for an action method.</param>
/// <returns>The generated URL.</returns>
/// <remarks>
/// <para>
/// The value of <see cref="UrlActionContext.Host" /> should be a trusted value. Relying on the value of the current request
/// can allow untrusted input to influence the resulting URI unless the <c>Host</c> header has been validated.
/// See the deployment documentation for instructions on how to properly validate the <c>Host</c> header in
/// your deployment environment.
/// </para>
/// </remarks>
string Action(UrlActionContext actionContext);
/// <summary>
@ -65,19 +74,36 @@ namespace Microsoft.AspNetCore.Mvc
/// Generates a URL with an absolute path, which contains the route name, route values, protocol to use, host
/// name, and fragment specified by <see cref="UrlRouteContext"/>. Generates an absolute URL if
/// <see cref="UrlActionContext.Protocol"/> and <see cref="UrlActionContext.Host"/> are non-<c>null</c>.
/// See the remarks section for important security information.
/// </summary>
/// <param name="routeContext">The context object for the generated URLs for a route.</param>
/// <returns>The generated URL.</returns>
/// <remarks>
/// <para>
/// The value of <see cref="UrlRouteContext.Host" /> should be a trusted value. Relying on the value of the current request
/// can allow untrusted input to influence the resulting URI unless the <c>Host</c> header has been validated.
/// See the deployment documentation for instructions on how to properly validate the <c>Host</c> header in
/// your deployment environment.
/// </para>
/// </remarks>
string RouteUrl(UrlRouteContext routeContext);
/// <summary>
/// Generates an absolute URL for the specified <paramref name="routeName"/> and route
/// <paramref name="values"/>, which contains the protocol (such as "http" or "https") and host name from the
/// current request.
/// current request. See the remarks section for important security information.
/// </summary>
/// <param name="routeName">The name of the route that is used to generate URL.</param>
/// <param name="values">An object that contains route values.</param>
/// <returns>The generated absolute URL.</returns>
/// <remarks>
/// <para>
/// This method uses the value of <see cref="HttpRequest.Host"/> to populate the host section of the generated URI.
/// Relying on the value of the current request can allow untrusted input to influence the resulting URI unless
/// the <c>Host</c> header has been validated. See the deployment documentation for instructions on how to properly
/// validate the <c>Host</c> header in your deployment environment.
/// </para>
/// </remarks>
string Link(string routeName, object values);
}
}

View File

@ -115,7 +115,8 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
internal static string GetAssemblyLocation(Assembly assembly)
{
if (Uri.TryCreate(assembly.CodeBase, UriKind.Absolute, out var result) && result.IsFile)
if (Uri.TryCreate(assembly.CodeBase, UriKind.Absolute, out var result) &&
result.IsFile && string.IsNullOrWhiteSpace(result.Fragment))
{
return result.LocalPath;
}

View File

@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc.Core;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Routing;
@ -108,7 +106,7 @@ namespace Microsoft.AspNetCore.Mvc
/// <summary>
/// Generates a URL with an absolute path for an action method, which contains the specified
/// <paramref name="action"/> name, <paramref name="controller"/> name, route <paramref name="values"/>, and
/// <paramref name="protocol"/> to use.
/// <paramref name="protocol"/> to use. See the remarks section for important security information.
/// </summary>
/// <param name="helper">The <see cref="IUrlHelper"/>.</param>
/// <param name="action">The name of the action method.</param>
@ -116,6 +114,14 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="values">An object that contains route values.</param>
/// <param name="protocol">The protocol for the URL, such as "http" or "https".</param>
/// <returns>The generated URL.</returns>
/// <remarks>
/// <para>
/// This method uses the value of <see cref="HttpRequest.Host"/> to populate the host section of the generated URI.
/// Relying on the value of the current request can allow untrusted input to influence the resulting URI unless
/// the <c>Host</c> header has been validated. See the deployment documentation for instructions on how to properly
/// validate the <c>Host</c> header in your deployment environment.
/// </para>
/// </remarks>
public static string Action(
this IUrlHelper helper,
string action,
@ -136,7 +142,7 @@ namespace Microsoft.AspNetCore.Mvc
/// <paramref name="action"/> name, <paramref name="controller"/> name, route <paramref name="values"/>,
/// <paramref name="protocol"/> to use, and <paramref name="host"/> name.
/// Generates an absolute URL if the <paramref name="protocol"/> and <paramref name="host"/> are
/// non-<c>null</c>.
/// non-<c>null</c>. See the remarks section for important security information.
/// </summary>
/// <param name="helper">The <see cref="IUrlHelper"/>.</param>
/// <param name="action">The name of the action method.</param>
@ -145,6 +151,14 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="protocol">The protocol for the URL, such as "http" or "https".</param>
/// <param name="host">The host name for the URL.</param>
/// <returns>The generated URL.</returns>
/// <remarks>
/// <para>
/// The value of <paramref name="host"/> should be a trusted value. Relying on the value of the current request
/// can allow untrusted input to influence the resulting URI unless the <c>Host</c> header has been validated.
/// See the deployment documentation for instructions on how to properly validate the <c>Host</c> header in
/// your deployment environment.
/// </para>
/// </remarks>
public static string Action(
this IUrlHelper helper,
string action,
@ -166,7 +180,7 @@ namespace Microsoft.AspNetCore.Mvc
/// <paramref name="action"/> name, <paramref name="controller"/> name, route <paramref name="values"/>,
/// <paramref name="protocol"/> to use, <paramref name="host"/> name, and <paramref name="fragment"/>.
/// Generates an absolute URL if the <paramref name="protocol"/> and <paramref name="host"/> are
/// non-<c>null</c>.
/// non-<c>null</c>. See the remarks section for important security information.
/// </summary>
/// <param name="helper">The <see cref="IUrlHelper"/>.</param>
/// <param name="action">The name of the action method.</param>
@ -176,6 +190,14 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="host">The host name for the URL.</param>
/// <param name="fragment">The fragment for the URL.</param>
/// <returns>The generated URL.</returns>
/// <remarks>
/// <para>
/// The value of <paramref name="host"/> should be a trusted value. Relying on the value of the current request
/// can allow untrusted input to influence the resulting URI unless the <c>Host</c> header has been validated.
/// See the deployment documentation for instructions on how to properly validate the <c>Host</c> header in
/// your deployment environment.
/// </para>
/// </remarks>
public static string Action(
this IUrlHelper helper,
string action,
@ -253,13 +275,22 @@ namespace Microsoft.AspNetCore.Mvc
/// <summary>
/// Generates a URL with an absolute path for the specified route <paramref name="routeName"/> and route
/// <paramref name="values"/>, which contains the specified <paramref name="protocol"/> to use.
/// <paramref name="values"/>, which contains the specified <paramref name="protocol"/> to use. See the
/// remarks section for important security information.
/// </summary>
/// <param name="helper">The <see cref="IUrlHelper"/>.</param>
/// <param name="routeName">The name of the route that is used to generate URL.</param>
/// <param name="values">An object that contains route values.</param>
/// <param name="protocol">The protocol for the URL, such as "http" or "https".</param>
/// <returns>The generated URL.</returns>
/// <remarks>
/// <para>
/// This method uses the value of <see cref="HttpRequest.Host"/> to populate the host section of the generated URI.
/// Relying on the value of the current request can allow untrusted input to influence the resulting URI unless
/// the <c>Host</c> header has been validated. See the deployment documentation for instructions on how to properly
/// validate the <c>Host</c> header in your deployment environment.
/// </para>
/// </remarks>
public static string RouteUrl(
this IUrlHelper helper,
string routeName,
@ -279,6 +310,7 @@ namespace Microsoft.AspNetCore.Mvc
/// <paramref name="values"/>, which contains the specified <paramref name="protocol"/> to use and
/// <paramref name="host"/> name. Generates an absolute URL if
/// <see cref="UrlActionContext.Protocol"/> and <see cref="UrlActionContext.Host"/> are non-<c>null</c>.
/// See the remarks section for important security information.
/// </summary>
/// <param name="helper">The <see cref="IUrlHelper"/>.</param>
/// <param name="routeName">The name of the route that is used to generate URL.</param>
@ -286,6 +318,14 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="protocol">The protocol for the URL, such as "http" or "https".</param>
/// <param name="host">The host name for the URL.</param>
/// <returns>The generated URL.</returns>
/// <remarks>
/// <para>
/// The value of <paramref name="host"/> should be a trusted value. Relying on the value of the current request
/// can allow untrusted input to influence the resulting URI unless the <c>Host</c> header has been validated.
/// See the deployment documentation for instructions on how to properly validate the <c>Host</c> header in
/// your deployment environment.
/// </para>
/// </remarks>
public static string RouteUrl(
this IUrlHelper helper,
string routeName,
@ -306,6 +346,7 @@ namespace Microsoft.AspNetCore.Mvc
/// <paramref name="values"/>, which contains the specified <paramref name="protocol"/> to use,
/// <paramref name="host"/> name and <paramref name="fragment"/>. Generates an absolute URL if
/// <see cref="UrlActionContext.Protocol"/> and <see cref="UrlActionContext.Host"/> are non-<c>null</c>.
/// See the remarks section for important security information.
/// </summary>
/// <param name="helper">The <see cref="IUrlHelper"/>.</param>
/// <param name="routeName">The name of the route that is used to generate URL.</param>
@ -314,6 +355,14 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="host">The host name for the URL.</param>
/// <param name="fragment">The fragment for the URL.</param>
/// <returns>The generated URL.</returns>
/// <remarks>
/// <para>
/// The value of <paramref name="host"/> should be a trusted value. Relying on the value of the current request
/// can allow untrusted input to influence the resulting URI unless the <c>Host</c> header has been validated.
/// See the deployment documentation for instructions on how to properly validate the <c>Host</c> header in
/// your deployment environment.
/// </para>
/// </remarks>
public static string RouteUrl(
this IUrlHelper helper,
string routeName,
@ -382,7 +431,8 @@ namespace Microsoft.AspNetCore.Mvc
=> Page(urlHelper, pageName, pageHandler, values, protocol: null);
/// <summary>
/// Generates a URL with an absolute path for the specified <paramref name="pageName"/>.
/// Generates a URL with an absolute path for the specified <paramref name="pageName"/>. See the remarks section
/// for important security information.
/// </summary>
/// <param name="urlHelper">The <see cref="IUrlHelper"/>.</param>
/// <param name="pageName">The page name to generate the url for.</param>
@ -390,6 +440,14 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="values">An object that contains route values.</param>
/// <param name="protocol">The protocol for the URL, such as "http" or "https".</param>
/// <returns>The generated URL.</returns>
/// <remarks>
/// <para>
/// This method uses the value of <see cref="HttpRequest.Host"/> to populate the host section of the generated URI.
/// Relying on the value of the current request can allow untrusted input to influence the resulting URI unless
/// the <c>Host</c> header has been validated. See the deployment documentation for instructions on how to properly
/// validate the <c>Host</c> header in your deployment environment.
/// </para>
/// </remarks>
public static string Page(
this IUrlHelper urlHelper,
string pageName,
@ -399,7 +457,8 @@ namespace Microsoft.AspNetCore.Mvc
=> Page(urlHelper, pageName, pageHandler, values, protocol, host: null, fragment: null);
/// <summary>
/// Generates a URL with an absolute path for the specified <paramref name="pageName"/>.
/// Generates a URL with an absolute path for the specified <paramref name="pageName"/>. See the remarks section for
/// important security information.
/// </summary>
/// <param name="urlHelper">The <see cref="IUrlHelper"/>.</param>
/// <param name="pageName">The page name to generate the url for.</param>
@ -408,6 +467,14 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="protocol">The protocol for the URL, such as "http" or "https".</param>
/// <param name="host">The host name for the URL.</param>
/// <returns>The generated URL.</returns>
/// <remarks>
/// <para>
/// The value of <paramref name="host"/> should be a trusted value. Relying on the value of the current request
/// can allow untrusted input to influence the resulting URI unless the <c>Host</c> header has been validated.
/// See the deployment documentation for instructions on how to properly validate the <c>Host</c> header in
/// your deployment environment.
/// </para>
/// </remarks>
public static string Page(
this IUrlHelper urlHelper,
string pageName,
@ -418,7 +485,8 @@ namespace Microsoft.AspNetCore.Mvc
=> Page(urlHelper, pageName, pageHandler, values, protocol, host, fragment: null);
/// <summary>
/// Generates a URL with an absolute path for the specified <paramref name="pageName"/>.
/// Generates a URL with an absolute path for the specified <paramref name="pageName"/>. See the remarks section for
/// important security information.
/// </summary>
/// <param name="urlHelper">The <see cref="IUrlHelper"/>.</param>
/// <param name="pageName">The page name to generate the url for.</param>
@ -428,6 +496,14 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="host">The host name for the URL.</param>
/// <param name="fragment">The fragment for the URL.</param>
/// <returns>The generated URL.</returns>
/// <remarks>
/// <para>
/// The value of <paramref name="host"/> should be a trusted value. Relying on the value of the current request
/// can allow untrusted input to influence the resulting URI unless the <c>Host</c> header has been validated.
/// See the deployment documentation for instructions on how to properly validate the <c>Host</c> header in
/// your deployment environment.
/// </para>
/// </remarks>
public static string Page(
this IUrlHelper urlHelper,
string pageName,

View File

@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
{
// Arrange
var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
var codeBase = "file://x/file/Assembly.dll";
var codeBase = "file://x:/file/Assembly.dll";
var expected = new Uri(codeBase).LocalPath;
var assembly = new TestAssembly
{
@ -109,6 +109,54 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
Assert.Equal(expected, actual);
}
[Fact]
public void GetAssemblyLocation_CodeBase_HasPoundCharacterUnixPath()
{
var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
var expected = @"/etc/#NIN/dotnetcore/tryx/try1.dll";
var assembly = new TestAssembly
{
CodeBaseSettable = "file:///etc/#NIN/dotnetcore/tryx/try1.dll",
LocationSettable = expected,
};
// Act
var actual = RelatedAssemblyAttribute.GetAssemblyLocation(assembly);
Assert.Equal(expected, actual);
}
[Fact]
public void GetAssemblyLocation_CodeBase_HasPoundCharacterUNCPath()
{
var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
var expected = @"\\server\#NIN\dotnetcore\tryx\try1.dll";
var assembly = new TestAssembly
{
CodeBaseSettable = "file://server/#NIN/dotnetcore/tryx/try1.dll",
LocationSettable = expected,
};
// Act
var actual = RelatedAssemblyAttribute.GetAssemblyLocation(assembly);
Assert.Equal(expected, actual);
}
[Fact]
public void GetAssemblyLocation_CodeBase_HasPoundCharacterDOSPath()
{
var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
var expected = @"C:\#NIN\dotnetcore\tryx\try1.dll";
var assembly = new TestAssembly
{
CodeBaseSettable = "file:///C:/#NIN/dotnetcore/tryx/try1.dll",
LocationSettable = expected,
};
// Act
var actual = RelatedAssemblyAttribute.GetAssemblyLocation(assembly);
Assert.Equal(expected, actual);
}
private class TestAssembly : Assembly
{
public override AssemblyName GetName()

View File

@ -325,7 +325,5 @@ namespace Microsoft.AspNetCore.Mvc.Routing
EndpointMetadataCollection.Empty,
null);
}
private class SuppressLinkGenerationMetadata : ISuppressLinkGenerationMetadata { }
}
}