diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-07-30 13:11:43 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-07-31 13:33:09 +0300 |
commit | ddee9ccbe1ebe57a8752b3318952e2541b2b34ca (patch) | |
tree | 5f30ec3a7b2283e44d93382d428fa835b021298b /app/src | |
parent | d0cd6af04fbc022a24b068cae5b36205d72435b9 (diff) |
#633: harden user parsing
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java index 524bd2a07..66e5089d7 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java @@ -303,7 +303,7 @@ public class JsonToEntityParser { if (owner.isJsonPrimitive()) {//TODO: remove if, let only else! DeckLog.verbose("owner is Primitive, skipping"); } else - fullBoard.setOwner(parseUser(owner.getAsJsonObject())); + fullBoard.setOwner(parseUser(owner)); } }, e); return fullBoard; @@ -315,7 +315,7 @@ public class JsonToEntityParser { if (aclJson.has("participant") && !aclJson.get("participant").isJsonNull()) { makeTraceableIfFails(() -> { - User participant = parseUser(aclJson.get("participant").getAsJsonObject()); + User participant = parseUser(aclJson.get("participant")); acl.setUser(participant); acl.setType(aclJson.get("type").getAsLong()); acl.setBoardId(aclJson.get("boardId").getAsLong()); @@ -362,7 +362,7 @@ public class JsonToEntityParser { for (JsonElement assignedUser : assignedUsers) { JsonObject userJson = assignedUser.getAsJsonObject(); if (userJson.has("participant") && !userJson.get("participant").isJsonNull()) { - users.add(parseUser(userJson.get("participant").getAsJsonObject())); + users.add(parseUser(userJson.get("participant"))); } } fullCard.setAssignedUsers(users); @@ -388,10 +388,7 @@ public class JsonToEntityParser { card.setCommentsUnread(e.get("commentsUnread").getAsInt()); JsonElement owner = e.get("owner"); if (owner != null) { - if (owner.isJsonPrimitive()) {//TODO: remove if, let only else! - DeckLog.verbose("owner is Primitive, skipping"); - } else - fullCard.setOwner(parseUser(owner.getAsJsonObject())); + fullCard.setOwner(parseUser(owner)); } card.setArchived(e.get("archived").getAsBoolean()); }, e); @@ -430,14 +427,27 @@ public class JsonToEntityParser { return a; } - protected static User parseUser(JsonObject e) { - DeckLog.verbose(e.toString()); + protected static User parseUser(JsonElement userElement) { + DeckLog.verbose(userElement.toString()); + if (userElement.isJsonNull()){ + return null; + } User user = new User(); makeTraceableIfFails(() -> { - user.setDisplayname(getNullAsEmptyString(e.get("displayname"))); - user.setPrimaryKey(getNullAsEmptyString(e.get("primaryKey"))); - user.setUid(getNullAsEmptyString(e.get("uid"))); - }, e); + + if (userElement.isJsonPrimitive()) { + String uid = userElement.getAsString(); + user.setDisplayname(uid); + user.setPrimaryKey(uid); + user.setUid(uid); + } else { + JsonObject userJson = userElement.getAsJsonObject(); + user.setDisplayname(getNullAsEmptyString(userJson.get("displayname"))); + user.setPrimaryKey(getNullAsEmptyString(userJson.get("primaryKey"))); + user.setUid(getNullAsEmptyString(userJson.get("uid"))); + } + + }, userElement); return user; } |