rspec/rules/S5147/java/rule.adoc
2022-02-04 16:28:24 +00:00

55 lines
1.4 KiB
Plaintext

include::../description.adoc[]
== Noncompliant Code Example
For the https://mongodb.github.io/mongo-java-driver/[MongoDB Java Driver]:
[source,java]
----
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws UnknownHostException
{
String input = req.getParameter("input");
MongoClient mongoClient = new MongoClient();
DB database = mongoClient.getDB("exampleDatabase");
DBCollection collection = database.getCollection("exampleCollection");
BasicDBObject query = new BasicDBObject();
query.put("$where", "this.field == \"" + input + "\""); // Noncompliant
}
----
== Compliant Solution
For the https://docs.mongodb.com/drivers/java/sync/current/[MongoDB Java Driver]:
[source,java]
----
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws UnknownHostException
{
String input = req.getParameter("input");
MongoClient mongoClient = new MongoClient();
DB database = mongoClient.getDB("ExampleDatabase");
DBCollection collection = database.getCollection("exampleCollection");
BasicDBObject query = new BasicDBObject();
query.put("field", input);
}
----
include::../see.adoc[]
include::./see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
endif::env-github,rspecator-view[]