@@ -58,6 +58,15 @@ private class ViewCall extends MethodCall {
58
58
59
59
/** Gets the name of the MVC controller that this call is made from, if any. */
60
60
string getControllerName ( ) { result + "Controller" = this .getController ( ) .getName ( ) }
61
+
62
+ /** Gets the name of the Area that the controller of this call belongs to, if any. */
63
+ string getAreaName ( ) {
64
+ exists ( Attribute attr |
65
+ attr = this .getController ( ) .getAnAttribute ( ) and
66
+ attr .getType ( ) .hasQualifiedName ( "Microsoft.AspNetCore.Mvc" , "AreaAttribute" ) and
67
+ result = attr .getArgument ( 0 ) .( StringLiteral ) .getValue ( )
68
+ )
69
+ }
61
70
}
62
71
63
72
/** A compiler-generated Razor page. */
@@ -110,17 +119,21 @@ private predicate viewCallRefersToPageRelative(ViewCall vc, RazorPage rp) {
110
119
111
120
/** Gets the `i`th template for view discovery. */
112
121
private string getViewSearchTemplate ( int i ) {
113
- i = 0 and result = "/Views/{1}/{0}.cshtml"
122
+ i = 0 and result = "/Areas/{2}/Views/{1}/{0}.cshtml"
123
+ or
124
+ i = 1 and result = "/Areas/{2}/Views/Shared/{0}.cshtml"
114
125
or
115
- i = 1 and result = "/Views/Shared /{0}.cshtml"
126
+ i = 2 and result = "/Views/{1} /{0}.cshtml"
116
127
or
117
- i = 2 and result = getAViewSearchTemplateInCode ( )
128
+ i = 3 and result = "/Views/Shared/{0}.cshtml"
129
+ or
130
+ i = 4 and result = getAViewSearchTemplateInCode ( )
118
131
}
119
132
120
133
/** Gets an additional template used for view discovery defined in code. */
121
134
private string getAViewSearchTemplateInCode ( ) {
122
135
exists ( StringLiteral str , MethodCall addCall |
123
- addCall .getTarget ( ) .hasQualifiedName ( "System.Collections.Generic" , "IList" , "Add" ) and
136
+ addCall .getTarget ( ) .hasName ( "Add" ) and
124
137
DataFlow:: localExprFlow ( str , addCall .getArgument ( 0 ) ) and
125
138
addCall .getQualifier ( ) = getAViewLocationList ( ) and
126
139
result = str .getValue ( )
@@ -134,8 +147,8 @@ private Expr getAViewLocationList() {
134
147
.getProperty ( )
135
148
.hasQualifiedName ( "Microsoft.AspNetCore.Mvc.Razor" , "RazorViewEngineOptions" ,
136
149
[
137
- "ViewLocationFormats" , "PageViewLocationFormats" , " AreaViewLocationFormats",
138
- "AreaPageViewLocationFormats"
150
+ "ViewLocationFormats" , "AreaViewLocationFormats" ,
151
+ //"PageViewLocationFormats", "AreaPageViewLocationFormats"
139
152
] )
140
153
}
141
154
@@ -145,13 +158,21 @@ private class RelativeViewCallFilepath extends NormalizableFilepath {
145
158
int idx_ ;
146
159
147
160
RelativeViewCallFilepath ( ) {
148
- exists ( string template | template = getViewSearchTemplate ( idx_ ) |
149
- this =
150
- template .replaceAll ( "{0}" , vc_ .getActionName ( ) ) .replaceAll ( "{1}" , vc_ .getControllerName ( ) )
151
- or
152
- not exists ( vc_ .getControllerName ( ) ) and
153
- not template .matches ( "%{1}%" ) and
154
- this = template .replaceAll ( "{0}" , vc_ .getActionName ( ) )
161
+ exists ( string template , string sub2 , string sub1 , string sub0 |
162
+ template = getViewSearchTemplate ( idx_ )
163
+ |
164
+ (
165
+ if template .matches ( "%{2}%" )
166
+ then sub2 = template .replaceAll ( "{2}" , vc_ .getAreaName ( ) )
167
+ else sub2 = template
168
+ ) and
169
+ (
170
+ if template .matches ( "%{1}%" )
171
+ then sub1 = sub2 .replaceAll ( "{1}" , vc_ .getControllerName ( ) )
172
+ else sub1 = sub2
173
+ ) and
174
+ sub0 = sub1 .replaceAll ( "{0}" , vc_ .getActionName ( ) ) and
175
+ this = sub0
155
176
)
156
177
}
157
178
0 commit comments