From afce680ad9e1cbebdbe05325e9c72d632d6fb30f Mon Sep 17 00:00:00 2001 From: Raman Arora <raman@basistech.com> Date: Fri, 10 Jul 2020 16:40:21 -0400 Subject: [PATCH] Addressed review comments. --- .../datamodel/CommunicationsManager.java | 10 ++++---- .../datamodel/CommunicationsUtils.java | 23 +++++++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/bindings/java/src/org/sleuthkit/datamodel/CommunicationsManager.java b/bindings/java/src/org/sleuthkit/datamodel/CommunicationsManager.java index 63540360a..4fefb1060 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/CommunicationsManager.java +++ b/bindings/java/src/org/sleuthkit/datamodel/CommunicationsManager.java @@ -332,12 +332,12 @@ public Account getAccount(org.sleuthkit.datamodel.Account.Type accountType, Stri * instances and between all recipient account instances. All account * instances must be from the same data source. * - * @param sender sender account - * @param recipients list of recipients - * @param sourceArtifact Artifact that relationships were derived from - * @param relationshipType The type of relationships to be created + * @param sender Sender account, may be null. + * @param recipients List of recipients, may be empty. + * @param sourceArtifact Artifact that relationships were derived from. + * @param relationshipType The type of relationships to be created. * @param dateTime Date of communications/relationship, as epoch - * seconds + * seconds. * * * @throws org.sleuthkit.datamodel.TskCoreException diff --git a/bindings/java/src/org/sleuthkit/datamodel/CommunicationsUtils.java b/bindings/java/src/org/sleuthkit/datamodel/CommunicationsUtils.java index b5b784c12..2484b1e16 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/CommunicationsUtils.java +++ b/bindings/java/src/org/sleuthkit/datamodel/CommunicationsUtils.java @@ -140,16 +140,13 @@ public static boolean isValidPhoneNumber(String phoneNum) { return false; } - // short min length allows of dial codes. - if (phoneNum.length() < MIN_PHONENUMBER_LEN) { - return false; - } - + String trimmedPhoneNum = phoneNum.trim(); + // A phone number may have a leading '+', special telephony chars, or digits. // Anything else implies an invalid phone number. - for (int i = 0; i < phoneNum.length(); i++) { - if (!((i == 0 && phoneNum.charAt(i) == '+') - || isValidPhoneChar(phoneNum.charAt(i)))) { + for (int i = 0; i < trimmedPhoneNum.length(); i++) { + if (!((trimmedPhoneNum.charAt(i) == '+' && i == 0) // a '+' is allowed only at the beginning + || isValidPhoneChar(trimmedPhoneNum.charAt(i)))) { return false; } } @@ -157,6 +154,13 @@ public static boolean isValidPhoneNumber(String phoneNum) { return true; } + /** + * Checks if the given character is a valid character for a phone number. + * + * @param ch Character to check. + * + * @return True, if its a valid phone number character, false, otherwise. + */ private static boolean isValidPhoneChar(char ch) { return Character.isSpaceChar(ch) || Character.isDigit(ch) @@ -186,8 +190,7 @@ public static boolean isValidEmailAddress(String emailAddress) { } if (emailAddress.contains("@") == false - || emailAddress.contains(".") == false - || emailAddress.length() < 5) { + || emailAddress.contains(".") == false ) { return false; } -- GitLab