diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-09-04 14:18:21 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2020-09-04 14:18:21 +0300 |
commit | 4fe00e6dae09640bb333a92c90d76d9aa35a29e2 (patch) | |
tree | 6a0fc23c2f571118507274ed8a37fa4ddaf236ba /app/src/main/java/it/niedermann/nextcloud/deck/util | |
parent | 76beaca12884481b59ac3f110af85222514eae0f (diff) |
#671 fixed code to fit tests
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/util')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/util/ProjectUtil.java | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/ProjectUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/ProjectUtil.java index f8041c514..1ff2d3460 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/ProjectUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/ProjectUtil.java @@ -41,9 +41,16 @@ public class ProjectUtil { * @return extracted and parsed values as long[] with length 1-2 */ public static long[] extractBoardIdAndCardIdFromUrl(@NonNull String url) { + if (url == null) { + throw new IllegalArgumentException("provided url is null"); + } + url = url.trim(); // extract important part - String[] splitByPrefix = url.split(".*/index\\.php/apps/deck/#/board/"); + String[] splitByPrefix = url.split(".*index\\.php/apps/deck/#/board/"); // split into board- and card part + if (splitByPrefix == null || splitByPrefix.length < 2) { + throw new IllegalArgumentException("this doesn't seem to be an URL containing the board ID"); + } String[] splitBySeparator = splitByPrefix[1].split("/card/"); // remove any unexpected stuff @@ -54,11 +61,24 @@ public class ProjectUtil { splitBySeparator[0] = splitBySeparator[0].split("/")[0]; } + if (splitBySeparator == null || splitBySeparator.length < 1) { + throw new IllegalArgumentException("this doesn't seem to be a valid URL containing the board ID"); + } + // return result + long boardId = Long.parseLong(splitBySeparator[0]); + if (boardId < 1) { + throw new IllegalArgumentException("invalid boardId: "+boardId); + } if (splitBySeparator.length == 1) { - return new long[]{Long.parseLong(splitBySeparator[0])}; + return new long[]{boardId}; } else if (splitBySeparator.length == 2) { - return new long[]{Long.parseLong(splitBySeparator[0]), Long.parseLong(splitBySeparator[1])}; + long cardId = Long.parseLong(splitBySeparator[1]); + if (cardId > 0) { + return new long[]{boardId, cardId}; + } else { + return new long[]{boardId}; + } } else { throw new IllegalArgumentException("could not parse URL for board- and/or card-ID"); } |