Skip to content

Commit 6a929c3

Browse files
wtgodbeJohn LuoTanayParikhcaptainsafiapranavkm
authored
Update SDK (#33187)
* Update SDK * Add diagnostic for tracing in test * Try disable publish trimming * Revert "Try disable publish trimming" This reverts commit 766ae32. * Add BuiltInComInteropSupport * Update global.json * Update global.json * Fix analyzer warning and clean up workarounds * Fix up more analyzer warnings * Fix CA1846 issues in WebEncoders and Http * Fix CA1845 warnings in Logging.AzureAppServices * Fix CA1845 warning in RazorPagesRazorViewEngineOptionsSetup * Fix warning in FileProviderRazorProjectFileSystem * Disable span warnings in tests * Re-ordering * Downgrade CA1846 to suggestion for projects Co-authored-by: John Luo <[email protected]> Co-authored-by: Tanay Parikh <[email protected]> Co-authored-by: Safia Abdalla <[email protected]> Co-authored-by: Safia Abdalla <[email protected]> Co-authored-by: Pranav K <[email protected]>
1 parent 4f2214a commit 6a929c3

File tree

21 files changed

+46
-17
lines changed

21 files changed

+46
-17
lines changed

.editorconfig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ dotnet_diagnostic.CA1840.severity = warning
147147
dotnet_diagnostic.CA1841.severity = warning
148148

149149
# CA1845: Use span-based 'string.Concat'
150-
dotnet_diagnostic.CA1845.severity = warning
150+
dotnet_diagnostic.CA1845.severity = suggestion
151151

152152
# CA1846: Prefer AsSpan over Substring
153153
dotnet_diagnostic.CA1846.severity = warning
@@ -186,5 +186,10 @@ dotnet_diagnostic.CA1837.severity = suggestion
186186
dotnet_diagnostic.CA1838.severity = suggestion
187187
# CA1841: Prefer Dictionary.Contains methods
188188
dotnet_diagnostic.CA1841.severity = suggestion
189+
# CA1845: Use span-based 'string.Concat'
190+
dotnet_diagnostic.CA1845.severity = suggestion
191+
# CA1846: Prefer AsSpan over Substring
192+
dotnet_diagnostic.CA1846.severity = suggestion
189193
# CA2012: Use ValueTask correctly
190194
dotnet_diagnostic.CA2012.severity = suggestion
195+

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"sdk": {
3-
"version": "6.0.100-preview.5.21264.3"
3+
"version": "6.0.100-preview.6.21308.9"
44
},
55
"tools": {
6-
"dotnet": "6.0.100-preview.5.21264.3",
6+
"dotnet": "6.0.100-preview.6.21308.9",
77
"runtimes": {
88
"dotnet/x64": [
99
"2.1.27",

src/Components/WebView/WebView/src/QueryString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public QueryString Add(QueryString other)
193193
}
194194

195195
// ?name1=value1 Add ?name2=value2 returns ?name1=value1&name2=value2
196-
return new QueryString(Value + "&" + other.Value.Substring(1));
196+
return new QueryString(string.Concat(Value, "&", other.Value.AsSpan(1)));
197197
}
198198

199199
/// <summary>

src/Hosting/test/testassets/BasicLinkedApp/BasicLinkedApp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<PublishTrimmed>true</PublishTrimmed>
77
<TrimMode>link</TrimMode>
88
<ILLinkTreatWarningsAsErrors>false</ILLinkTreatWarningsAsErrors>
9+
<!-- Revert after issue in https://github.com/dotnet/aspnetcore/pull/33187 is resolved. -->
10+
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
911
</PropertyGroup>
1012

1113
<ItemGroup>

src/Http/Http.Abstractions/src/QueryString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public QueryString Add(QueryString other)
187187
}
188188

189189
// ?name1=value1 Add ?name2=value2 returns ?name1=value1&name2=value2
190-
return new QueryString(Value + "&" + other.Value.Substring(1));
190+
return new QueryString(string.Concat(Value, "&", other.Value.AsSpan(1)));
191191
}
192192

193193
/// <summary>

src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public async Task PathMatchAction_BranchTaken(string matchPath, string basePath,
8989
await app.Invoke(context);
9090

9191
Assert.Equal(200, context.Response.StatusCode);
92-
Assert.Equal(basePath + requestPath.Substring(0, matchPath.Length), (string)context.Items["test.PathBase"]!);
92+
Assert.Equal(string.Concat(basePath, requestPath.AsSpan(0, matchPath.Length)), (string)context.Items["test.PathBase"]!);
9393
Assert.Equal(requestPath.Substring(matchPath.Length), context.Items["test.Path"]);
9494
}
9595

src/Http/Routing/src/Patterns/RoutePatternParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ private string DebuggerToString()
568568
}
569569
else
570570
{
571-
return _template.Substring(0, _index) + "|" + _template.Substring(_index);
571+
return string.Concat(_template.Substring(0, _index), "|", _template.Substring(_index));
572572
}
573573
}
574574
}

src/Identity/test/InMemory.Test/FunctionalTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ private static async Task<TestServer> CreateServer(Action<IServiceCollection> co
332332
}
333333
else if (req.Path.StartsWithSegments(new PathString("/pwdLogin"), out remainder))
334334
{
335-
var isPersistent = bool.Parse(remainder.Value.Substring(1));
335+
var isPersistent = bool.Parse(remainder.Value.AsSpan(1));
336336
var result = await signInManager.PasswordSignInAsync("hao", TestPassword, isPersistent, false);
337337
res.StatusCode = result.Succeeded ? 200 : 500;
338338
}

src/Logging.AzureAppServices/src/BlobAppendReferenceWrapper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ private static void AppendBlockQuery(UriBuilder uriBuilder)
8989
// and set the property with the combined string.
9090
var queryToAppend = "comp=appendblock";
9191
if (uriBuilder.Query != null && uriBuilder.Query.Length > 1)
92+
#if NETFRAMEWORK || NETSTANDARD
9293
uriBuilder.Query = uriBuilder.Query.Substring(1) + "&" + queryToAppend;
94+
#else
95+
uriBuilder.Query = string.Concat(uriBuilder.Query.AsSpan(1), "&", queryToAppend);
96+
#endif
9397
else
9498
uriBuilder.Query = queryToAppend;
9599
}

src/Middleware/ResponseCompression/src/ResponseCompressionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public bool CheckRequestAcceptsCompression(HttpContext context)
258258

259259
if (slashPos >= 0)
260260
{
261-
var partialMimeType = mimeType!.Substring(0, slashPos.Value) + "/*";
261+
var partialMimeType = string.Concat(mimeType!.AsSpan(0, slashPos.Value), "/*");
262262
return ShouldCompressExact(partialMimeType);
263263
}
264264

src/Middleware/tools/RazorPageGenerator/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private string ProcessFileIncludes()
218218
var includeFileName = cshtmlContent.Substring(startIndex + startMatch.Length, endIndex - (startIndex + startMatch.Length));
219219
Console.WriteLine(" Inlining file {0}", includeFileName);
220220
var includeFileContent = File.ReadAllText(System.IO.Path.Combine(basePath, includeFileName));
221-
cshtmlContent = cshtmlContent.Substring(0, startIndex) + includeFileContent + cshtmlContent.Substring(endIndex + endMatch.Length);
221+
cshtmlContent = string.Concat(cshtmlContent.AsSpan(0, startIndex), includeFileContent, cshtmlContent.AsSpan(endIndex + endMatch.Length));
222222
startIndex = startIndex + includeFileContent.Length;
223223
}
224224
return cshtmlContent;

src/Mvc/Mvc.Core/src/Routing/ViewEnginePath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static string CombinePath(string first, string second)
4040
}
4141
else
4242
{
43-
result = first.Substring(0, index + 1) + second;
43+
result = string.Concat(first.AsSpan(0, index + 1), second);
4444
}
4545

4646
return ResolvePath(result);

src/Mvc/Mvc.Razor.RuntimeCompilation/src/FileProviderRazorProjectFileSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private static string JoinPath(string path1, string path2)
8686
var hasLeadingSlash = path2.StartsWith("/", StringComparison.Ordinal);
8787
if (hasLeadingSlash && hasTrailingSlash)
8888
{
89-
return path1 + path2.Substring(1);
89+
return string.Concat(path1, path2.AsSpan(1));
9090
}
9191
else if (hasLeadingSlash || hasTrailingSlash)
9292
{

src/Mvc/Mvc.RazorPages/src/DependencyInjection/RazorPagesRazorViewEngineOptionsSetup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private static string CombinePath(string path1, string path2)
7272
}
7373
else if (path1.EndsWith("/", StringComparison.Ordinal) && path2.StartsWith("/", StringComparison.Ordinal))
7474
{
75-
return path1 + path2.Substring(1);
75+
return string.Concat(path1, path2.AsSpan(1));
7676
}
7777

7878
return path1 + "/" + path2;

src/Security/samples/CustomPolicyProvider/Authorization/MinimumAgeAuthorizeAttribute.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using Microsoft.AspNetCore.Authorization;
23

34
namespace CustomPolicyProvider
@@ -20,7 +21,7 @@ public int Age
2021
{
2122
get
2223
{
23-
if (int.TryParse(Policy.Substring(POLICY_PREFIX.Length), out var age))
24+
if (int.TryParse(Policy.AsSpan(POLICY_PREFIX.Length), out var age))
2425
{
2526
return age;
2627
}

src/Servers/Kestrel/samples/LargeResponseApp/Startup.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.IO;
56
using System.Net;
67
using System.Text;
@@ -22,7 +23,7 @@ public void Configure(IApplicationBuilder app)
2223
app.Run(async (context) =>
2324
{
2425
var path = context.Request.Path;
25-
if (!path.HasValue || !int.TryParse(path.Value.Substring(1), out var numChunks))
26+
if (!path.HasValue || !int.TryParse(path.Value.AsSpan(1), out var numChunks))
2627
{
2728
numChunks = _defaultNumChunks;
2829
}
@@ -49,7 +50,7 @@ public static Task Main(string[] args)
4950
})
5051
.UseContentRoot(Directory.GetCurrentDirectory())
5152
.UseStartup<Startup>();
52-
})
53+
})
5354
.Build();
5455

5556
return host.RunAsync();

src/Shared/CommandLineUtils/CommandLine/AnsiConsole.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ public void WriteLine(string message)
9292
{
9393
case 'm':
9494
int value;
95+
#if NETFRAMEWORK
9596
if (int.TryParse(message.Substring(startIndex, endIndex - startIndex), out value))
97+
#else
98+
if (int.TryParse(message.AsSpan(startIndex, endIndex - startIndex), out value))
99+
#endif
96100
{
97101
switch (value)
98102
{

src/Testing/src/AssemblyTestLog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public IServiceProvider CreateLoggerServices(ITestOutputHelper output, string cl
131131
throw new InvalidOperationException("Output file path could not be constructed due to max path length restrictions. Please shorten test assembly, class or method names.");
132132
}
133133

134-
testName = testName.Substring(0, testNameLength / 2) + testName.Substring(testName.Length - testNameLength / 2, testNameLength / 2);
134+
testName = string.Concat(testName.AsSpan(0, testNameLength / 2).ToString(), testName.AsSpan(testName.Length - testNameLength / 2, testNameLength / 2).ToString());
135135

136136
_globalLogger.LogWarning($"To prevent long paths test name was shortened to {testName}.");
137137
}

src/WebEncoders/src/Testing/HtmlTestEncoder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ public override void Encode(TextWriter output, string value, int startIndex, int
7676
}
7777

7878
output.Write("HtmlEncode[[");
79+
#if NETFRAMEWORK || NETSTANDARD
7980
output.Write(value.Substring(startIndex, characterCount));
81+
#else
82+
output.Write(value.AsSpan(startIndex, characterCount));
83+
#endif
8084
output.Write("]]");
8185
}
8286

src/WebEncoders/src/Testing/JavaScriptTestEncoder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ public override void Encode(TextWriter output, string value, int startIndex, int
7676
}
7777

7878
output.Write("JavaScriptEncode[[");
79+
#if NETFRAMEWORK || NETSTANDARD
7980
output.Write(value.Substring(startIndex, characterCount));
81+
#else
82+
output.Write(value.AsSpan(startIndex, characterCount));
83+
#endif
8084
output.Write("]]");
8185
}
8286

src/WebEncoders/src/Testing/UrlTestEncoder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ public override void Encode(TextWriter output, string value, int startIndex, int
7676
}
7777

7878
output.Write("UrlEncode[[");
79+
#if NETFRAMEWORK || NETSTANDARD
7980
output.Write(value.Substring(startIndex, characterCount));
81+
#else
82+
output.Write(value.AsSpan(startIndex, characterCount));
83+
#endif
8084
output.Write("]]");
8185
}
8286

0 commit comments

Comments
 (0)