Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a100832
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 20, 2021
903d164
Update dependencies from https://github.com/dotnet/runtime build 2021…
dotnet-maestro[bot] Aug 20, 2021
d046abf
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 20, 2021
8566b38
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 20, 2021
2008974
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 20, 2021
903be6a
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 21, 2021
97d9233
Update dependencies from https://github.com/dotnet/runtime build 2021…
dotnet-maestro[bot] Aug 21, 2021
10d5834
Update dependencies from https://github.com/dotnet/runtime build 2021…
dotnet-maestro[bot] Aug 22, 2021
439b977
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 22, 2021
866e4df
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 23, 2021
b469ef0
Update dependencies from https://github.com/dotnet/runtime build 2021…
dotnet-maestro[bot] Aug 23, 2021
93d559d
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 23, 2021
4fd1e36
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 24, 2021
6e4a318
Update dependencies from https://github.com/dotnet/runtime build 2021…
dotnet-maestro[bot] Aug 24, 2021
1e7fe92
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 24, 2021
d233f5c
Respond to nullable annotations of `StringSegment`
dougbu Aug 24, 2021
5b9aa8a
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 24, 2021
9330eed
!fixup!
dougbu Aug 24, 2021
0c0378d
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 25, 2021
cb404b1
Update dependencies from https://github.com/dotnet/runtime build 2021…
dotnet-maestro[bot] Aug 25, 2021
b908867
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 26, 2021
c4580c1
Update dependencies from https://github.com/dotnet/runtime build 2021…
dotnet-maestro[bot] Aug 26, 2021
b19a7e8
Handle more nullable expressions
dougbu Aug 25, 2021
47ca366
Merge branch 'main' into darc-main-fcbf8a54-42e6-4ded-9535-034b26dfd6ba
dougbu Aug 27, 2021
5c65c52
Update dependencies from https://github.com/dotnet/efcore build 20210…
dotnet-maestro[bot] Aug 27, 2021
0dc7277
Update dependencies from https://github.com/dotnet/runtime build 2021…
dotnet-maestro[bot] Aug 27, 2021
4bff1b7
Latest nullability updates
dougbu Aug 27, 2021
ab619a9
Remove some `StringSegment.Value` `null` forgiveness and extra handling
dougbu Aug 28, 2021
e3db44a
Update dependencies from https://github.com/dotnet/runtime build 2021…
dotnet-maestro[bot] Aug 28, 2021
16a960b
!fixup! Handle `IsNullOrEmpty(...)` metadata lack
dougbu Aug 28, 2021
dbea160
!fixup! Use `ToString()` instead of suppression
dougbu Aug 28, 2021
9550049
Update dependencies from https://github.com/dotnet/runtime build 2021…
dotnet-maestro[bot] Aug 28, 2021
9ac655f
Update `KnownHeaders`
dougbu Aug 29, 2021
543efec
Do generated JS files need to change?
dougbu Aug 29, 2021
992d844
!fixup! Allow `Charset` to be `null`
dougbu Aug 29, 2021
1404d93
Update dependencies from https://github.com/dotnet/runtime build 2021…
dotnet-maestro[bot] Aug 29, 2021
0d79864
!fixup! Adjust to fix failing tests
dougbu Aug 29, 2021
f484c66
!fixup! React to `HttpResponse.ContentType` change
dougbu Aug 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Latest nullability updates
- handle Microsoft.Extensions.FileProviders.Abstractions nullability annotations (dotnet/runtime#57405)
- handle Microsoft.Extensions.FileProviders.Physical nullability annotations (dotnet/runtime#57409)
- !fixup! improve `HttpConnectionDispatcher.GetConnectionToken(...)` and its use
  • Loading branch information
dougbu committed Aug 28, 2021
commit 4bff1b70847430df26166cb6cc4a19c98897dcdf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ManifestDirectoryInfo(ManifestDirectory directory, DateTimeOffset lastMod

public string? PhysicalPath => null;

public string? Name => Directory.Name;
public string Name => Directory.Name;

public DateTimeOffset LastModified { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ManifestFileInfo(Assembly assembly, ManifestFile file, DateTimeOffset las

public string? PhysicalPath => null;

public string? Name => ManifestFile.Name;
public string Name => ManifestFile.Name;

public DateTimeOffset LastModified { get; }

Expand Down
3 changes: 2 additions & 1 deletion src/Middleware/StaticFiles/src/DefaultFilesMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public Task Invoke(HttpContext context)
&& Helpers.IsGetOrHeadMethod(context.Request.Method)
&& Helpers.TryMatchPath(context, _matchUrl, forDirectory: true, subpath: out var subpath))
{
var dirContents = _fileProvider.GetDirectoryContents(subpath.Value);
// TryMatchPath will not output an empty subpath when it returns true.
var dirContents = _fileProvider.GetDirectoryContents(subpath.Value!);
if (dirContents.Exists)
{
// Check if any of our default files exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public Task Invoke(HttpContext context)

private bool TryGetDirectoryInfo(PathString subpath, out IDirectoryContents contents)
{
contents = _fileProvider.GetDirectoryContents(subpath.Value);
// TryMatchPath will not output an empty subpath when it returns true. This is called only in that case.
contents = _fileProvider.GetDirectoryContents(subpath.Value!);
return contents.Exists;
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/Middleware/StaticFiles/src/StaticFileContext.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
Expand Down Expand Up @@ -47,6 +43,11 @@ internal struct StaticFileContext

public StaticFileContext(HttpContext context, StaticFileOptions options, ILogger logger, IFileProvider fileProvider, string? contentType, PathString subPath)
{
if (!subPath.HasValue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tratcher StaticFileMiddleware.ValidatePath(...) returns true when it sets subPath to PathString.Empty. In turn, PathString.Empty shows HasValue == false because that property uses !string.IsNullOrEmpty(Value). This feels like a bug -- an empty value is still a value and should get passed this check. Thoughts❔

For now, I'm going to change PathString.HasValue but I suspect my next iteration won't fix all the test failures. You have a bit of time ☹️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed my mind because the result is extra allocations e.g. UsePathBaseExtensions.UsePathBase(...) will add an unnecessary UsePathBaseMiddleware. Will instead change this to check subPath.Value == null.

{
throw new ArgumentNullException(nameof(subPath));
}

_context = context;
_options = options;
_request = context.Request;
Expand Down Expand Up @@ -109,11 +110,11 @@ private set

public string SubPath => _subPath.Value!;

public string PhysicalPath => _fileInfo.PhysicalPath;
public string PhysicalPath => _fileInfo.PhysicalPath ?? string.Empty;

public bool LookupFileInfo()
{
_fileInfo = _fileProvider.GetFileInfo(_subPath.Value);
_fileInfo = _fileProvider.GetFileInfo(SubPath);
if (_fileInfo.Exists)
{
_length = _fileInfo.Length;
Expand Down Expand Up @@ -264,7 +265,7 @@ public void ApplyResponseHeaders(int statusCode)
_response.ContentLength = _length;
}

_options.OnPrepareResponse(new StaticFileResponseContext(_context, _fileInfo!));
_options.OnPrepareResponse(new StaticFileResponseContext(_context, _fileInfo));
}

public PreconditionState GetPreconditionState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public FileProviderRazorProjectItem(IFileInfo fileInfo, string basePath, string
public override bool Exists => FileInfo.Exists;

/// <inheritdoc/>
public override string PhysicalPath => FileInfo.PhysicalPath;
public override string PhysicalPath => FileInfo.PhysicalPath ?? string.Empty;

/// <inheritdoc/>
public override string? RelativePhysicalPath
Expand Down
6 changes: 3 additions & 3 deletions src/Shared/MediaType/ReadOnlyMediaTypeHeaderValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ReadOnlyMediaTypeHeaderValue(string mediaType)
/// </summary>
/// <param name="mediaType">The <see cref="StringSegment"/> with the media type.</param>
public ReadOnlyMediaTypeHeaderValue(StringSegment mediaType)
: this(mediaType.Buffer, mediaType.Offset, mediaType.Length)
: this(mediaType.Buffer ?? string.Empty, mediaType.Offset, mediaType.Length)
{
}

Expand Down Expand Up @@ -146,7 +146,7 @@ private static bool TryGetSuffixLength(StringSegment subType, out int suffixLeng
var startPos = subType.Offset + subType.Length - 1;
for (var currentPos = startPos; currentPos >= subType.Offset; currentPos--)
{
if (subType.Buffer[currentPos] == '+')
if (subType.Buffer![currentPos] == '+')
{
suffixLength = startPos - currentPos;
return true;
Expand Down Expand Up @@ -357,7 +357,7 @@ public bool TryGetLastParameter(StringSegment parameterName, out StringSegment p
// charset.Value might be an invalid encoding name as in charset=invalid.
// For that reason, we catch the exception thrown by Encoding.GetEncoding
// and return null instead.
return charset.HasValue ? Encoding.GetEncoding(charset.Value) : null;
return charset.HasValue ? Encoding.GetEncoding(charset.Value!) : null;
}
catch (Exception)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/StaticWebAssets/StaticWebAssetsFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public StaticWebAssetsFileInfo(string name, IFileInfo source)

public long Length => _source.Length;

public string PhysicalPath => _source.PhysicalPath;
public string PhysicalPath => _source.PhysicalPath ?? string.Empty;

public DateTimeOffset LastModified => _source.LastModified;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task ExecuteAsync(HttpContext context, HttpConnectionDispatcherOpti

HttpConnectionContext? connectionContext = null;
var connectionToken = GetConnectionToken(context);
if (connectionToken != null)
if (!StringValues.IsNullOrEmpty(connectionToken))
{
_manager.TryGetConnection(connectionToken, out connectionContext);
}
Expand Down Expand Up @@ -381,7 +381,7 @@ private static bool ServerHasWebSockets(IFeatureCollection features)
return features.Get<IHttpWebSocketFeature>() != null;
}

private static string GetConnectionToken(HttpContext context) => context.Request.Query["id"].ToString();
private static StringValues GetConnectionToken(HttpContext context) => context.Request.Query["id"];

private async Task ProcessSend(HttpContext context, HttpConnectionDispatcherOptions options)
{
Expand Down