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



##########
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:
       I think 0 shouldn't be invalid, although we could make more validators 
based on strictness. According to 
[wikipedia](https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers)
   - 0: In programming APIs (not in communication between hosts), requests a 
system-allocated (dynamic). java.net.InetSocketAddress is designed this way (A 
valid port value is between 0 and 65535. A port number of zero will let the 
system pick up an ephemeral port in a bind operation.) and according the this 
standard we can assume other API's follow it too.
   - 0-1023: well known ports
   - 1024-49151: Registered ports by IANA
   - 49152-65535: Ephemeral ports typically used by TCP and UDP connections
   
   I'm thinking about a few options.
   
   - Creating different PORT validators for well known, registered and 
ephemeral ports.
   - Including 0 or not with any of these.
   
   
   
   




-- 
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:
us...@infra.apache.org


Reply via email to