You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/04/26 15:44:40 UTC

[GitHub] [nifi] exceptionfactory commented on a change in pull request #5028: NIFI-8325: Complete SNMP refactor: SNMP GET and SET processors rework, unit tests added

exceptionfactory commented on a change in pull request #5028:
URL: https://github.com/apache/nifi/pull/5028#discussion_r620420099



##########
File path: nifi-commons/nifi-utils/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
##########
@@ -151,7 +152,24 @@ public ValidationResult validate(final String subject, final String value, final
         }
     };
 
-    public static final Validator PORT_VALIDATOR = createLongValidator(1, 65535, true);
+    public static final Validator NETWORK_ADDRESS_VALIDATOR = new Validator() {
+        private final Pattern ipv4Pattern = Pattern.compile("^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\.(?!$)|$)){4}$");
+
+        @Override
+        public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
+
+            final String reason = "not a valid IP address";
+            final boolean isValidInetAddress = "localhost".equals(value) || isValid(value);
+            return new ValidationResult.Builder().subject(subject).input(value).explanation(reason).valid(isValidInetAddress).build();
+        }
+
+        private boolean isValid(final String email) {
+            Matcher matcher = ipv4Pattern.matcher(email);
+            return matcher.matches();
+        }
+    };
+
+    public static final Validator PORT_VALIDATOR = createLongValidator(0, 65535, true);

Review comment:
       This change breaks existing unit tests that expect `0` to be an invalid port number.  Is there a particular reason for this change?  If so, the existing unit test should be updated, but having `0` as a port number may not work as expected in some existing components.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org