Skip to content

Commit df39008

Browse files
authored
Merge pull request #44152 from dotnet-maestro-bot/merge/release/7.0-to-main
[automated] Merge branch 'release/7.0' => 'main'
2 parents c918cf9 + bb856e7 commit df39008

File tree

9 files changed

+57
-25
lines changed

9 files changed

+57
-25
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Users referenced in this file will automatically be requested as reviewers for PRs that modify the given paths.
22
# See https://help.github.com/articles/about-code-owners/
33

4-
* @Pilchie
54
/**/PublicAPI.*Shipped.txt @dotnet/aspnet-api-review
65
/global.json @dotnet/aspnet-build @dougbu @wtgodbe
76
/.azure/ @dotnet/aspnet-build @dougbu @wtgodbe

eng/Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<DotNetProjects Include="
161161
$(RepoRoot)src\Framework\App.Ref\src\Microsoft.AspNetCore.App.Ref.csproj;
162162
$(RepoRoot)src\Framework\App.Ref.Internal\src\Microsoft.AspNetCore.App.Ref.Internal.csproj;
163+
$(RepoRoot)src\Framework\AspNetCoreAnalyzers\test\Microsoft.AspNetCore.App.Analyzers.Test.csproj;
163164
$(RepoRoot)src\Framework\test\Microsoft.AspNetCore.App.UnitTests.csproj;
164165
$(RepoRoot)src\Caching\**\*.*proj;
165166
$(RepoRoot)src\DefaultBuilder\**\*.*proj;

eng/targets/Helix.Common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<HelixQueueDebian11>(Debian.11.Amd64.Open)[email protected]/dotnet-buildtools/prereqs:debian-11-helix-amd64-20211001171307-0ece9b3</HelixQueueDebian11>
66
<HelixQueueFedora34>(Fedora.34.Amd64.Open)[email protected]/dotnet-buildtools/prereqs:fedora-34-helix-20210924174119-4f64125</HelixQueueFedora34>
77
<HelixQueueMariner>(Mariner)[email protected]/dotnet-buildtools/prereqs:cbl-mariner-1.0-helix-20210528192219-92bf620</HelixQueueMariner>
8-
<HelixQueueArmDebian11>(Debian.11.Arm64.Open)Ubuntu.2004[email protected]/dotnet-buildtools/prereqs:debian-11-helix-arm64v8-20211001171229-97d8652</HelixQueueArmDebian11>
8+
<HelixQueueArmDebian11>(Debian.11.Arm64.Open)Ubuntu.1804[email protected]/dotnet-buildtools/prereqs:debian-11-helix-arm64v8-20211001171229-97d8652</HelixQueueArmDebian11>
99

1010
<!-- Do not attempt to override global property. -->
1111
<RunQuarantinedTests Condition=" '$(RunQuarantinedTests)' == '' ">false</RunQuarantinedTests>

eng/test-configuration.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
{"testName": {"contains": "POST_ServerAbort_ClientReceivesAbort"}},
1818
{"testName": {"contains": "POST_ServerAbortAfterWrite_ClientReceivesAbort"}},
1919
{"testAssembly": {"contains": "IIS"}},
20+
{"testAssembly": {"contains": "Template"}},
2021
{"failureMessage": {"contains":"(Site is started but no worker process found)"}},
2122
{"failureMessage": {"contains": "network disconnected"}}
2223
],

src/Framework/AspNetCoreAnalyzers/src/Analyzers/RouteHandlers/DetectMisplacedLambdaAttribute.cs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics;
45
using System.Linq;
56
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -22,23 +23,17 @@ private static void DetectMisplacedLambdaAttribute(
2223
// Hello();
2324
// return "foo";
2425
// }
25-
IMethodSymbol? methodSymbol = null;
2626

27-
// () => Hello() has a single child which is a BlockOperation so we check to see if
28-
// expression associated with that operation is an invocation expression
29-
if (lambda.ChildOperations.FirstOrDefault().Syntax is InvocationExpressionSyntax innerInvocation)
27+
// All lambdas have a single child which is a BlockOperation. We search ChildOperations for
28+
// the invocation expression.
29+
if (lambda.ChildOperations.Count != 1 || lambda.ChildOperations.FirstOrDefault() is not IBlockOperation blockOperation)
3030
{
31-
methodSymbol = lambda.Symbol;
32-
}
33-
34-
if (lambda.ChildOperations.FirstOrDefault().ChildOperations.FirstOrDefault() is IReturnOperation returnOperation
35-
&& returnOperation.ReturnedValue is IInvocationOperation returnedInvocation)
36-
{
37-
methodSymbol = returnedInvocation.TargetMethod;
31+
Debug.Fail("Expected a single top-level BlockOperation for all lambdas.");
32+
return;
3833
}
3934

4035
// If no method definition was found for the lambda, then abort.
41-
if (methodSymbol is null)
36+
if (GetReturnedInvocation(blockOperation) is not IMethodSymbol methodSymbol)
4237
{
4338
return;
4439
}
@@ -73,5 +68,38 @@ static bool IsInValidNamespace(INamespaceSymbol? @namespace)
7368

7469
return false;
7570
}
71+
72+
static IMethodSymbol? GetReturnedInvocation(IBlockOperation blockOperation)
73+
{
74+
foreach (var op in blockOperation.ChildOperations.Reverse())
75+
{
76+
if (op is IReturnOperation returnStatement)
77+
{
78+
if (returnStatement.ReturnedValue is IInvocationOperation invocationReturn)
79+
{
80+
return invocationReturn.TargetMethod;
81+
}
82+
83+
// Sometimes expression backed lambdas include an IReturnOperation with a null ReturnedValue
84+
// right after the IExpressionStatementOperation whose Operation is the real ReturnedValue,
85+
// so we keep looking backwards rather than returning null immediately.
86+
}
87+
else if (op is IExpressionStatementOperation expression)
88+
{
89+
if (expression.Operation is IInvocationOperation invocationExpression)
90+
{
91+
return invocationExpression.TargetMethod;
92+
}
93+
94+
return null;
95+
}
96+
else
97+
{
98+
return null;
99+
}
100+
}
101+
102+
return null;
103+
}
76104
}
77105
}

src/Framework/AspNetCoreAnalyzers/test/Verifiers/CSharpWebApplicationBuilderCodeFixVerifier.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public WebApplicationBuilderAnalyzerTest()
6868
TrimAssemblyExtension(typeof(Microsoft.Extensions.Hosting.HostingHostBuilderExtensions).Assembly.Location),
6969
TrimAssemblyExtension(typeof(Microsoft.AspNetCore.Builder.ConfigureHostBuilder).Assembly.Location),
7070
TrimAssemblyExtension(typeof(Microsoft.AspNetCore.Builder.ConfigureWebHostBuilder).Assembly.Location),
71+
TrimAssemblyExtension(typeof(Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions).Assembly.Location),
7172
TrimAssemblyExtension(typeof(Microsoft.AspNetCore.Hosting.HostingAbstractionsWebHostBuilderExtensions).Assembly.Location),
7273
TrimAssemblyExtension(typeof(Microsoft.Extensions.Logging.ILoggingBuilder).Assembly.Location),
7374
TrimAssemblyExtension(typeof(Microsoft.Extensions.Logging.ConsoleLoggerExtensions).Assembly.Location),

src/Http/Routing/src/RouteEndpointDataSource.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,13 @@ private RouteEndpointBuilder CreateRouteEndpointBuilder(
168168
{
169169
DisplayName = displayName,
170170
ApplicationServices = _applicationServices,
171-
Metadata = { handler.Method },
172171
};
173172

173+
if (isRouteHandler)
174+
{
175+
builder.Metadata.Add(handler.Method);
176+
}
177+
174178
if (entry.HttpMethods is not null)
175179
{
176180
builder.Metadata.Add(new HttpMethodMetadata(entry.HttpMethods));

src/Http/Routing/test/UnitTests/Builder/RequestDelegateEndpointRouteBuilderExtensionsTest.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,9 @@ public void MapEndpoint_AttributesCollectedAsMetadata()
190190
// Assert
191191
var endpointBuilder1 = GetRouteEndpointBuilder(builder);
192192
Assert.Equal("/", endpointBuilder1.RoutePattern.RawText);
193-
Assert.Equal(3, endpointBuilder1.Metadata.Count);
194-
Assert.Equal(((RequestDelegate)Handle).Method, endpointBuilder1.Metadata[0]);
195-
Assert.IsType<Attribute1>(endpointBuilder1.Metadata[1]);
196-
Assert.IsType<Attribute2>(endpointBuilder1.Metadata[2]);
193+
Assert.Equal(2, endpointBuilder1.Metadata.Count);
194+
Assert.IsType<Attribute1>(endpointBuilder1.Metadata[0]);
195+
Assert.IsType<Attribute2>(endpointBuilder1.Metadata[1]);
197196
}
198197

199198
[Fact]
@@ -228,11 +227,10 @@ public void MapEndpoint_PrecedenceOfMetadata_BuilderMetadataReturned()
228227

229228
// As with the Delegate Map method overloads for route handlers, the attributes on the RequestDelegate
230229
// can override the HttpMethodMetadata. Extension methods could already do this.
231-
Assert.Equal(4, endpoint.Metadata.Count);
232-
Assert.Equal(((RequestDelegate)HandleHttpMetdata).Method, endpoint.Metadata[0]);
233-
Assert.Equal("METHOD", GetMethod(endpoint.Metadata[1]));
234-
Assert.Equal("ATTRIBUTE", GetMethod(endpoint.Metadata[2]));
235-
Assert.Equal("BUILDER", GetMethod(endpoint.Metadata[3]));
230+
Assert.Equal(3, endpoint.Metadata.Count);
231+
Assert.Equal("METHOD", GetMethod(endpoint.Metadata[0]));
232+
Assert.Equal("ATTRIBUTE", GetMethod(endpoint.Metadata[1]));
233+
Assert.Equal("BUILDER", GetMethod(endpoint.Metadata[2]));
236234

237235
Assert.Equal("BUILDER", endpoint.Metadata.GetMetadata<IHttpMethodMetadata>()?.HttpMethods.Single());
238236

0 commit comments

Comments
 (0)