2022-01-31 11:01:20 +01:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
|
|
For the https://mongodb.github.io/mongo-java-driver/[MongoDB Java Driver]:
|
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,java]
|
2022-01-31 11:01:20 +01:00
|
|
|
----
|
|
|
|
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]:
|
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,java]
|
2022-01-31 11:01:20 +01:00
|
|
|
----
|
|
|
|
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[]
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|