Skip to content

Commit 31b2ebd

Browse files
authored
Fix so all command responses correctly decode as UTF-8 (#64)
1 parent 5a42fe3 commit 31b2ebd

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# The LabKey Remote API Library for Java - Change Log
22

33
## version 6.1.0-SNAPSHOT
4+
*Released*: TBD
5+
* [Issue 49238](https://www.labkey.org/home/Developer/issues/issues-details.view?issueId=49238): Fix so all command responses correctly decode as UTF-8.
46

57
## version 6.0.0
68
*Released*: 1 December 2023
79
* Encode SQL parameters passed by `ExecuteSqlCommand` and `SqlExecuteCommand` to avoid rejection by web application firewalls
810
* Earliest compatible LabKey Server version: 23.9.0
9-
* These commands are no longer compatible with earlier versions of LabKey Server (23.8.x and before) by default, however,
11+
* These commands are no longer compatible with earlier versions of LabKey Server (23.8.x and before) by default. However,
1012
if targeting an older server, calling `ExecuteSqlCommand.setWafEncoding(false)` will restore the previous behavior.
1113
* Update HttpCore, JSON-java, Gradle Plugins, and Gradle versions
1214

@@ -51,7 +53,7 @@
5153
* `setJsonObject()` is now available only on `SimplePostCommand`. Custom `PostCommand` subclasses that need to post JSON are
5254
expected to override `getJsonObject()`.
5355
* Stop passing command subclasses when constructing every `CommandResponse`. The two response classes that need this now implement
54-
it without burdening all other commands.
56+
it without burdening all other commands.
5557
* Introduce `HasRequiredVersion` interface and use it when instantiating `CommandResponse` subclasses that need required version
5658
* Remove all `Command` copy constructors. Same rationale as the earlier removal of `copy` methods.
5759
* Switch `SelectRowsCommand` and `NAbRunsCommand` to post their parameters as JSON
@@ -65,8 +67,7 @@
6567

6668
## version 4.3.0
6769
*Released*: 11 January 2023
68-
* [Issue 47030](https://www.labkey.org/home/Developer/issues/issues-details.view?issueId=47030): Switch `SelectRowsCommand`
69-
and `NAbRunsCommand` to always use POST
70+
* [Issue 47030](https://www.labkey.org/home/Developer/issues/issues-details.view?issueId=47030): Switch `SelectRowsCommand` and `NAbRunsCommand` to always use POST
7071
* Add support for `includeTotalCount`, `includeMetadata`, and `ignoreFilter` flags to `BaseQueryCommand` and reconcile
7172
duplicate parameter handling code vs. SelectRowsCommand
7273
* Add support for `includeTitle` and `includeViewDataUrl` flags to `GetQueriesCommand`

src/org/labkey/remoteapi/Command.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public String getText() throws IOException
276276
if (_responseText != null)
277277
return _responseText;
278278

279-
try (Scanner s = new Scanner(_httpResponse.getEntity().getContent()).useDelimiter("\\A"))
279+
try (Scanner s = new Scanner(_httpResponse.getEntity().getContent(), StandardCharsets.UTF_8).useDelimiter("\\A"))
280280
{
281281
// Simple InputStream -> String conversion
282282
return s.hasNext() ? s.next() : "";
@@ -362,7 +362,7 @@ private void throwError(Response r, boolean throwByDefault) throws IOException,
362362
if (null != contentType && contentType.contains(CONTENT_TYPE_JSON))
363363
{
364364
// Parse JSON
365-
if (responseText != null && responseText.length() > 0)
365+
if (responseText != null && !responseText.isEmpty())
366366
{
367367
json = new JSONObject(responseText);
368368
if (json.has("exception"))
@@ -447,7 +447,7 @@ private URI createURI(Connection connection, String folderPath) throws URISyntax
447447
StringBuilder path = new StringBuilder(uri.getPath() == null || "".equals(uri.getPath()) ? "/" : uri.getPath());
448448

449449
//add the folderPath (if any)
450-
if (null != folderPath && folderPath.length() > 0)
450+
if (null != folderPath && !folderPath.isEmpty())
451451
{
452452
String folderPathNormalized = folderPath.replace('\\', '/');
453453
if (folderPathNormalized.charAt(0) == '/') // strip leading slash

0 commit comments

Comments
 (0)