Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/dotnet/.devcontainer/base.Dockerfile

# [Choice] .NET version: 7.0, 6.0, 5.0
ARG VARIANT="8.0"
# [Choice] .NET version: use "latest" or a specific version like "10.0"
ARG VARIANT="10.0"
FROM mcr.microsoft.com/vscode/devcontainers/dotnet
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v4
Expand All @@ -28,7 +28,7 @@ jobs:
languages: csharp

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
id: installdotnet
with:
dotnet-version: 10.0.x
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"dotnet-test-explorer.testProjectPath": "**/*Tests.csproj",
"editor.formatOnType": true,
"omnisharp.enableRoslynAnalyzers": true,
"omnisharp.organizeImportsOnFormat": true,
"omnisharp.useModernNet": true,
"omnisharp.enableMsBuildLoadProjectsOnDemand": true,
"omnisharp.enableEditorConfigSupport": true,
"dotnet.completion.showCompletionItemsFromUnimportedNamespaces": true
"dotnet.completion.showCompletionItemsFromUnimportedNamespaces": true,
"dotnet.formatting.organizeImportsOnFormat": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@
/// <summary>
/// Attempts to parse an API version from the specified namespace identifier.
/// </summary>
/// <param name="identifier">The namespace identifier to parse.</param>
/// <param name="identifier">The namespace identifier to parse. The identifier must start with
/// 'v', 'V', or '_' followed by a digit. The '_' prefix supports folder names that start with
/// a number, which causes Visual Studio to prepend an underscore to the namespace.</param>
/// <param name="apiVersion">The parsed <see cref="ApiVersion">API version</see> or <c>null</c>.</param>
/// <returns>True if parsing is successful; otherwise, false.</returns>
protected virtual bool TryParse( Text identifier, out ApiVersion? apiVersion )
Expand All @@ -157,21 +159,36 @@
return false;
}

// 'v' | 'V' : [<year> : ['_'] : <month> : ['_'] : <day>] : ['_'] : [<major> ['_' : <minor>]] : ['_'] : [<status>]
// 'v' | 'V' | '_' : [<year> : ['_'] : <month> : ['_'] : <day>] : ['_'] : [<major> ['_' : <minor>]] : ['_'] : [<status>]
//
// - v1
// - v1_1
// - v2_0_Beta
// - v20180401
// - v2018_04_01_1_1_Beta
// - _1
// - _1_1
// - _20180401
// - _2018_04_01
var ch = identifier[0];

if ( ch != 'v' && ch != 'V' )
if ( ch != 'v' && ch != 'V' && ch != '_' )
{
apiVersion = default;
return false;
}

if ( ch == '_' )
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This entire branch of logic doesn't make sense nor is there a test for this use case. What is this scenario? The only possibilities here are _, v, or V, none of which will parse as a valid ApiVersion. If there were only 2 characters, the next letter would always have to be a digit anyway; for example v1. This entire block doesn't appear to be necessary.

{
// '_' prefix requires the next character to be a digit;
// otherwise, it's just a regular identifier
if ( identifier.Length < 2 || !char.IsDigit( identifier[1] ) )
{
apiVersion = default;
return false;
}
}
Comment on lines +181 to +190

Check notice

Code scanning / CodeQL

Nested 'if' statements can be combined Note

These 'if' statements can be combined.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It definitely shouldn't be nested, but I'm not even sure it's necessary for this to exist


#if NETSTANDARD
identifier = identifier.Substring( 1 );
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ public void parse_should_return_no_versions()
{ "Contoso.Api.v2018_04_01_1_0_Beta.Controllers", "2018-04-01.1.0-Beta" },
{ "MyRestaurant.Vegetarian.Food.v1_1.Controllers", "1.1" },
{ "VersioningSample.V5.Controllers", "5.0" },
{ "_1", "1" },
{ "_1_1", "1.1" },
{ "_20180401", "2018-04-01" },
{ "_2018_04_01", "2018-04-01" },
{ "_2018_04_01_Beta", "2018-04-01-Beta" },
{ "_2018_04_01_1_0_Beta", "2018-04-01.1.0-Beta" },
{ "Contoso.Api._2018_04_01.Controllers", "2018-04-01" },
{ "Contoso.Api._1.Controllers", "1" },
{ "Contoso.Api._1_1.Controllers", "1.1" },
{ "Contoso.Api._0_9_Beta.Controllers", "0.9-Beta" },
};

public static TheoryData<string, string[]> NamespaceWithMultipleVersions => new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public partial class VersionByNamespaceConventionTest
{ "Contoso.Api.v2018_04_01_1_0_Beta.Controllers", "2018-04-01.1.0-Beta" },
{ "MyRestaurant.Vegetarian.Food.v1_1.Controllers", "1.1" },
{ "VersioningSample.V5.Controllers", "5.0" },
{ "_1", "1.0" },
{ "_1_1", "1.1" },
{ "_20180401", "2018-04-01" },
{ "_2018_04_01", "2018-04-01" },
{ "_2018_04_01_Beta", "2018-04-01-Beta" },
{ "_2018_04_01_1_0_Beta", "2018-04-01.1.0-Beta" },
{ "Contoso.Api._2018_04_01.Controllers", "2018-04-01" },
{ "Contoso.Api._1.Controllers", "1.0" },
{ "Contoso.Api._1_1.Controllers", "1.1" },
{ "Contoso.Api._0_9_Beta.Controllers", "0.9-Beta" },
};

private sealed class TestType : TypeDelegator
Expand Down