@@ -22,7 +22,8 @@ public class AttributeAnalyzer : DiagnosticAnalyzer
2222 ASP005ParameterSyntax . Descriptor ,
2323 ASP006ParameterRegex . Descriptor ,
2424 ASP007MissingParameter . Descriptor ,
25- ASP008ValidRouteParameterName . Descriptor ) ;
25+ ASP008ValidRouteParameterName . Descriptor ,
26+ ASP009LowercaseUrl . Descriptor ) ;
2627
2728 public override void Initialize ( AnalysisContext context )
2829 {
@@ -133,6 +134,17 @@ context.ContainingSymbol is IMethodSymbol method &&
133134 ? ImmutableDictionary < string , string > . Empty
134135 : ImmutableDictionary < string , string > . Empty . Add ( nameof ( Text ) , name ) ) ) ;
135136 }
137+
138+ if ( IsUpperCase ( segment , out var lowercase ) )
139+ {
140+ context . ReportDiagnostic (
141+ Diagnostic . Create (
142+ ASP009LowercaseUrl . Descriptor ,
143+ segment . Span . GetLocation ( ) ,
144+ lowercase == null
145+ ? ImmutableDictionary < string , string > . Empty
146+ : ImmutableDictionary < string , string > . Empty . Add ( nameof ( Text ) , lowercase ) ) ) ;
147+ }
136148 }
137149 }
138150 }
@@ -501,7 +513,8 @@ private static bool HasInvalidName(PathSegment segment, out Location location, o
501513 parameter . Name . EndsWith ( " " , StringComparison . OrdinalIgnoreCase ) )
502514 {
503515 location = parameter . Name . GetLocation ( ) ;
504- correctName = parameter . Name . ToString ( ) . Trim ( ) ;
516+ correctName = parameter . Name . ToString ( )
517+ . Trim ( ) ;
505518 return true ;
506519 }
507520
@@ -521,5 +534,28 @@ private static bool HasInvalidName(PathSegment segment, out Location location, o
521534 correctName = null ;
522535 return false ;
523536 }
537+
538+ private static bool IsUpperCase ( PathSegment segment , out string lowercase )
539+ {
540+ if ( segment . Parameter == null &&
541+ segment . Span . Length > 0 &&
542+ char . IsUpper ( segment . Span [ 0 ] ) )
543+ {
544+ for ( var i = 1 ; i < segment . Span . Length ; i ++ )
545+ {
546+ if ( char . IsUpper ( segment . Span [ i ] ) )
547+ {
548+ lowercase = null ;
549+ return false ;
550+ }
551+ }
552+
553+ lowercase = segment . Span . ToString ( ) . ToLower ( ) ;
554+ return true ;
555+ }
556+
557+ lowercase = null ;
558+ return false ;
559+ }
524560 }
525561}
0 commit comments