@@ -123,7 +123,55 @@ abstract class RenderCall extends MethodCall {
123123 // TODO: implicit renders in controller actions
124124}
125125
126- // A call to the `render` method within the context of a template.
126+ /**
127+ * A call to `render`, `render_to_body` or `render_to_string`, seen as an
128+ * `HttpResponse`.
129+ */
130+ private class RenderCallAsHttpResponse extends DataFlow:: CallNode , HTTP:: Server:: HttpResponse:: Range {
131+ RenderCallAsHttpResponse ( ) {
132+ this .asExpr ( ) .getExpr ( ) instanceof RenderCall or
133+ this .asExpr ( ) .getExpr ( ) instanceof RenderToCall
134+ }
135+
136+ // `render` is a very polymorphic method - all of these are valid calls:
137+ // render @user
138+ // render "path/to/template"
139+ // render html: "<html></html>"
140+ // render json: { "some" => "hash" }
141+ // render body: "some text"
142+ override DataFlow:: Node getBody ( ) {
143+ // A positional argument, e.g.
144+ // render @user
145+ // render "path/to/template"
146+ result = this .getArgument ( _) and
147+ not result .asExpr ( ) instanceof ExprNodes:: PairCfgNode
148+ or
149+ result = this .getKeywordArgument ( [ "html" , "json" , "body" , "inline" , "plain" , "js" , "file" ] )
150+ }
151+
152+ override DataFlow:: Node getMimetypeOrContentTypeArg ( ) {
153+ result = this .getKeywordArgument ( "content_type" )
154+ }
155+
156+ override string getMimetype ( ) {
157+ exists ( this .getKeywordArgument ( "json" ) ) and result = "application/json"
158+ or
159+ exists ( this .getKeywordArgument ( "plain" ) ) and result = "text/plain"
160+ or
161+ exists ( this .getKeywordArgument ( "html" ) ) and result = "text/html"
162+ or
163+ exists ( this .getKeywordArgument ( "xml" ) ) and result = "application/xml"
164+ or
165+ exists ( this .getKeywordArgument ( "js" ) ) and result = "text/javascript"
166+ or
167+ not exists ( this .getKeywordArgument ( [ "json" , "plain" , "html" , "xml" , "js" ] ) ) and
168+ result = super .getMimetype ( )
169+ }
170+
171+ override string getMimetypeDefault ( ) { result = "text/html" }
172+ }
173+
174+ /** A call to the `render` method within the context of a template. */
127175private class ActionViewRenderCall extends RenderCall , ActionViewContextCall { }
128176
129177/**
0 commit comments