[ 
https://issues.apache.org/jira/browse/IO-770?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17575136#comment-17575136
 ] 

Jiangwei Liu commented on IO-770:
---------------------------------

Hi Sita Geßner ,

I investigated this problem, the following may be helpful to you:

It is because that the result of the method 
FilenameUtils.isRFC3986HostName("sub_1.example.com") is false.
the pattern of the hostname is "^[a-zA-Z0-9][a-zA-Z0-9-]*$", and defined as:
Pattern REG_NAME_PART_PATTERN = Pattern.compile("^[a-zA-Z0-9][a-zA-Z0-9-]*$");

FYI:
"sub_1.example.com" is not a valid host name according to RFC 3986,
because the underscore(_) is not legal in domain names per RFC 1034.

> FilenameUtils#getFullPathNoEndSeparator has issues with windows and 
> underscore in hostname
> ------------------------------------------------------------------------------------------
>
>                 Key: IO-770
>                 URL: https://issues.apache.org/jira/browse/IO-770
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.7, 2.8.0, 2.9.0, 2.10.0, 2.11.0
>            Reporter: Sita Geßner
>            Priority: Major
>
> After updating commons-io to version 2.11.0 there is an issue with 
> FilenameUtils#getFullPathNoEndSeparator only when using Windows.
> When using Linux there are no problems.
> getFullPathNoEndSeparator returns  null if the hostname of the path contains 
> an underscore. This issue occured since version 2.7
> {code:java}
>     private static void commonsIo() {
>         final String result = getSubFolderFromFile(new 
> File("\\\\sub_1.example.com\\path\\subfolder\\test.pdf"));
>         // Fails in common-io:2.11.0 b/c result is null.
>         System.out.println("result should be \"subfolder\", but it is: " + 
> result);
>     }
>     private static String getSubFolderFromFile(final File file) {
>         return 
> FilenameUtils.getBaseName(FilenameUtils.getFullPathNoEndSeparator(file.getAbsolutePath()));
>     }
> {code}
> We know hostnames are not supposed to have underscores, but windows allows it 
> and  unfortunatly we have to deal with this.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to