@@ -283,23 +283,31 @@ class MessageBodyReaderRead extends Method {
283
283
}
284
284
}
285
285
286
+ private string getContentTypeString ( Expr e ) {
287
+ result = e .( CompileTimeConstantExpr ) .getStringValue ( )
288
+ or
289
+ exists ( Field jaxMediaType |
290
+ // Accesses to static fields on `MediaType` class do not have constant strings in the database
291
+ // so convert the field name to a content type string
292
+ jaxMediaType .getDeclaringType ( ) .hasQualifiedName ( getAJaxRsPackage ( "core" ) , "MediaType" ) and
293
+ jaxMediaType .getAnAccess ( ) = e and
294
+ // e.g. MediaType.TEXT_PLAIN => text/plain
295
+ result = jaxMediaType .getName ( ) .toLowerCase ( ) .replaceAll ( "_value" , "" ) .replaceAll ( "_" , "/" )
296
+ )
297
+ }
298
+
286
299
/** An `@Produces` annotation that describes which content types can be produced by this resource. */
287
300
class JaxRSProducesAnnotation extends JaxRSAnnotation {
288
301
JaxRSProducesAnnotation ( ) { this .getType ( ) .hasQualifiedName ( getAJaxRsPackage ( ) , "Produces" ) }
289
302
290
303
/**
291
304
* Gets a declared content type that can be produced by this resource.
292
305
*/
293
- string getADeclaredContentType ( ) {
294
- result = this .getAValue ( ) .( CompileTimeConstantExpr ) .getStringValue ( )
295
- or
296
- exists ( Field jaxMediaType |
297
- // Accesses to static fields on `MediaType` class do not have constant strings in the database
298
- // so convert the field name to a content type string
299
- jaxMediaType .getDeclaringType ( ) .hasQualifiedName ( getAJaxRsPackage ( "core" ) , "MediaType" ) and
300
- jaxMediaType .getAnAccess ( ) = this .getAValue ( ) and
301
- // e.g. MediaType.TEXT_PLAIN => text/plain
302
- result = jaxMediaType .getName ( ) .toLowerCase ( ) .replaceAll ( "_" , "/" )
306
+ Expr getADeclaredContentTypeExpr ( ) {
307
+ (
308
+ result = this .getAValue ( ) and not result instanceof ArrayInit
309
+ or
310
+ result = this .getAValue ( ) .( ArrayInit ) .getAnInit ( )
303
311
)
304
312
}
305
313
}
@@ -319,7 +327,8 @@ private class JaxRSXssSink extends XssSink {
319
327
|
320
328
not exists ( resourceMethod .getProducesAnnotation ( ) )
321
329
or
322
- resourceMethod .getProducesAnnotation ( ) .getADeclaredContentType ( ) = "text/plain"
330
+ getContentTypeString ( resourceMethod .getProducesAnnotation ( ) .getADeclaredContentTypeExpr ( ) ) =
331
+ "text/plain"
323
332
)
324
333
}
325
334
}
0 commit comments