Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 88f39eb

Browse files
committed
Always return an array for fields when using QueryBuilder
1 parent e60c2a8 commit 88f39eb

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22
- [UPGRADED] Optional OkHttp dependency to version 3.12.2.
3+
- [FIXED] Create an array of strings for QueryBuilder.fields() when a single field is provided.
34

45
# 2.17.0 (2019-05-23)
56
- [NEW] Added `com.cloudant.client.api.model.DbInfo#getDocDelCountLong()` to return

cloudant-client/src/main/java/com/cloudant/client/api/query/QueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public QueryBuilder useIndex(String designDocument, String indexName) {
191191
* @return String representation of query.
192192
*/
193193
public String build() {
194-
String fieldsString = this.fields == null ? null : Helpers.quote(this.fields);
194+
String fieldsString = this.fields == null ? null : Helpers.quote(this.fields, true);
195195
String sortString = this.sort == null ? null : quoteSort(this.sort);
196196
String limitString = this.limit == null ? null : Helpers.quote(this.limit);
197197
String skipString = this.skip == null ? null : Helpers.quote(this.skip);

cloudant-client/src/test/java/com/cloudant/tests/QueryTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ public void complexSelector2() {
251251
"{\"$eq\": \"de Vito\"}}, {\"Year\": {\"$eq\": 2001}}]}]}}", qb.build());
252252
}
253253

254+
// fields must always be an array of strings, even with a single field provided
255+
@Test
256+
public void basicSelector1WithField() {
257+
QueryBuilder qb = new QueryBuilder(eq("director", "Lars von Trier")).fields("_id");
258+
Assertions.assertEquals("{\"selector\": {\"director\": {\"$eq\": \"Lars von Trier\"}}, " +
259+
"\"fields\": [\"_id\"]}", qb.build());
260+
}
261+
254262
// "Selector basics"
255263
@Test
256264
public void basicSelector1WithFields() {

0 commit comments

Comments
 (0)