Skip to content

Commit f66f87f

Browse files
committed
Support underscore-prefixed API version identifiers
NamespaceParser now recognizes API version identifiers starting with '_', in addition to 'v' and 'V'. Added comprehensive tests to ensure correct parsing of underscore-prefixed version formats in various namespace scenarios.
1 parent 55496e3 commit f66f87f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Abstractions/src/Asp.Versioning.Abstractions/NamespaceParser.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,17 @@ protected virtual bool TryParse( Text identifier, out ApiVersion? apiVersion )
157157
return false;
158158
}
159159

160-
// 'v' | 'V' : [<year> : ['_'] : <month> : ['_'] : <day>] : ['_'] : [<major> ['_' : <minor>]] : ['_'] : [<status>]
160+
// 'v' | 'V' | '_' : [<year> : ['_'] : <month> : ['_'] : <day>] : ['_'] : [<major> ['_' : <minor>]] : ['_'] : [<status>]
161161
//
162162
// - v1
163163
// - v1_1
164164
// - v2_0_Beta
165165
// - v20180401
166166
// - v2018_04_01_1_1_Beta
167+
// - _2018_04_01
167168
var ch = identifier[0];
168169

169-
if ( ch != 'v' && ch != 'V' )
170+
if ( ch != 'v' && ch != 'V' && ch != '_' )
170171
{
171172
apiVersion = default;
172173
return false;

src/Abstractions/test/Asp.Versioning.Abstractions.Tests/NamespaceParserTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ public void parse_should_return_no_versions()
7070
{ "Contoso.Api.v2018_04_01_1_0_Beta.Controllers", "2018-04-01.1.0-Beta" },
7171
{ "MyRestaurant.Vegetarian.Food.v1_1.Controllers", "1.1" },
7272
{ "VersioningSample.V5.Controllers", "5.0" },
73+
{ "_1", "1" },
74+
{ "_1_1", "1.1" },
75+
{ "_0_9_Beta", "0.9-Beta" },
76+
{ "_20180401", "2018-04-01" },
77+
{ "_2018_04_01", "2018-04-01" },
78+
{ "_20180401_Beta", "2018-04-01-Beta" },
79+
{ "_2018_04_01_Beta", "2018-04-01-Beta" },
80+
{ "_2018_04_01_1_0_Beta", "2018-04-01.1.0-Beta" },
81+
{ "Contoso.Api._1.Controllers", "1" },
82+
{ "Contoso.Api._2018_04_01.Controllers", "2018-04-01" },
83+
{ "Contoso.Api._2018_04_01_Beta.Controllers", "2018-04-01-Beta" },
7384
};
7485

7586
public static TheoryData<string, string[]> NamespaceWithMultipleVersions => new()

0 commit comments

Comments
 (0)