You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Sebb (Jira)" <ji...@apache.org> on 2020/08/09 12:43:00 UTC

[jira] [Commented] (IO-552) FilenameUtils.concat fails if second argument (fullFilenameToAdd) starts with '~' (tilde)

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

Sebb commented on IO-552:
-------------------------

The '~' prefix is shell convention, and handled by the shell itself.
The string ~username is replaced by the home directory for the pathname.
The prefix ~/ is replaced by the current user directory.

Note that one can create a file/directory ~username by quoting it:

touch '~username'
mkdir '~username'

Also Java can create a directory as follows:

(new File("~username").mkdir();

It looks like FileNameUtils tries to emulate the behaviour of the shell.
If there are discrepancies, I guess the code should be adjusted to match the behaviour of the shell.

> FilenameUtils.concat fails if second argument (fullFilenameToAdd) starts with '~' (tilde)
> -----------------------------------------------------------------------------------------
>
>                 Key: IO-552
>                 URL: https://issues.apache.org/jira/browse/IO-552
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.2, 2.5
>         Environment: Windows 7 64bit, JavaVM 1.8 32bit
>            Reporter: Jochen Tümmers
>            Priority: Critical
>
> {{FilenameUtils.concat("c:/temp", "~abc.txt") returns "~abc.txt/" instead of "c:/temp/~abc.txt".}}
> As a result, the file would be created in the user's home directory instead of c:/temp.
> (Note: I Had to replace all instances of double backslashes that would normally appear in the java code with forward slashes as the editor cannot handle backslashes properly.)
> commons io 2.2. and 2.5 behave the same. 2.3 and 2.4 not tested.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)