[ https://issues.apache.org/jira/browse/IO-805?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17803833#comment-17803833 ]
Gary D. Gregory commented on IO-805: ------------------------------------ Note: This is called eventually from getPrefixLength() which does special odd things with "~". > FilenameUtils.isIPv4Address does not handle illegal integers > ------------------------------------------------------------ > > Key: IO-805 > URL: https://issues.apache.org/jira/browse/IO-805 > Project: Commons IO > Issue Type: Bug > Reporter: Hao Zhong > Priority: Major > > {code:java} > private static boolean isIPv4Address(final String name) { > final Matcher m = IPV4_PATTERN.matcher(name); > if (!m.matches() || m.groupCount() != 4) { > return false; > } // verify that address subgroups are legal > for (int i = 1; i <= 4; i++) { > final String ipSegment = m.group(i); > final int iIpSegment = Integer.parseInt(ipSegment); > if (iIpSegment > IPV4_MAX_OCTET_VALUE) { > return false; > } if (ipSegment.length() > 1 && > ipSegment.startsWith("0")) { > return false; > } } return true; > } {code} > In the above code, final int iIpSegment = Integer.parseInt(ipSegment) will > throw exceptions when ipSegment is illegal. > > The nearby isIPv6Address provides an example to handle the problem: > > {code:java} > private static boolean isIPv6Address(final String inet6Address) { > ... > try { octetInt = Integer.parseInt(octet, BASE_16); > } catch (final NumberFormatException e) { > return false; } > }{code} -- This message was sent by Atlassian Jira (v8.20.10#820010)