Bug 317513 - Cannot open files that start with a tilde
Summary: Cannot open files that start with a tilde
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kio
Classification: Frameworks and Libraries
Component: Open/save dialogs (show other bugs)
Version: 5.45.0
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: KIO Bugs
URL:
Keywords: usability
: 144220 262385 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-03-28 22:55 UTC by Dima Ryazanov
Modified: 2025-03-14 16:47 UTC (History)
7 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.13
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dima Ryazanov 2013-03-28 22:55:22 UTC
File dialog won't open files whose names start with "~". E.g., create a file named "~foo.txt" and try to open it in any KDE app.
Comment 1 Christoph Feck 2013-04-16 18:07:43 UTC
The tilde character is the UNIX way to reference the home directory.

http://en.wikipedia.org/wiki/Tilde#Directories_and_URLs
Comment 2 Christoph Feck 2013-07-08 02:13:49 UTC
*** Bug 262385 has been marked as a duplicate of this bug. ***
Comment 3 Dima Ryazanov 2013-11-16 00:30:38 UTC
Found another filename that doesn't work: ".txt

(I know it's a special character, but it's a valid filename.)
Comment 4 Christoph Feck 2013-11-16 12:10:20 UTC
Dima, that's bug 185433.
Comment 5 Nate Graham 2018-04-11 21:59:40 UTC
*** Bug 144220 has been marked as a duplicate of this bug. ***
Comment 6 Bug Janitor Service 2025-03-07 17:58:57 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/1831
Comment 7 Bug Janitor Service 2025-03-12 10:03:44 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kcoreaddons/-/merge_requests/489
Comment 8 Akseli Lahtinen 2025-03-13 10:55:07 UTC
Git commit 42d0c8b9be209c20538a4cb0b3865b676aa4fc44 by Akseli Lahtinen.
Committed on 13/03/2025 at 10:55.
Pushed by akselmo into branch 'master'.

KShell:tildeExpand: Return filename if homedir is empty

Often cache and automatic backup files are saved with ~ prefix. Our
tilde-expand method returns empty in cases where the `~file` does not
match an username.

In those cases, just return the filename instead.

Also updated autotest.

M  +1    -0    autotests/kshelltest.cpp
M  +5    -1    src/lib/util/kshell.cpp

https://invent.kde.org/frameworks/kcoreaddons/-/commit/42d0c8b9be209c20538a4cb0b3865b676aa4fc44
Comment 9 Dima Ryazanov 2025-03-13 17:06:27 UTC
What if there is a user named "file"? Then I'm still not allowed to open a file named "~file"? That's even more inconsistent now.

Also, we're talking about a file dialog, not a UNIX shell. If it's going to support tildes, should it also support quotes, backslashes, dollar signs, and so on?
Comment 10 Dima Ryazanov 2025-03-13 17:10:20 UTC
Also, regardless of any special characters, if I *click* a file, then that's the file that should be opened. It's pretty simple.
Comment 11 Nate Graham 2025-03-13 18:42:03 UTC
> What if there is a user named "file"?
Then there's a potential looming disaster, because depending on how your apps were programmed, when they try to save or delete such a file, they may end up copying it into the "file" user's home directory (confusing and wrong) or deleting the home directory entirely (utter catastrophe).

Such files are too dangerous and should not be named in that way. We already warn against this in our new file creator dialog, and will soon make it impossible to do anyway if the proposed name of the new file actually does overlap with the name of an existing user's account.
Comment 12 Akseli Lahtinen 2025-03-14 16:47:39 UTC
Git commit 26292d7d97d64c029424c5cf610053f2d8eb2e74 by Akseli Lahtinen.
Committed on 14/03/2025 at 16:47.
Pushed by akselmo into branch 'master'.

KNewFileMenu: Forbid saving file or folder with ~USERNAME as name

When creating new file or directory, check that any name which starts
with ~ does not resolve into a home directory on the machine.

This is due to an UNIX convention where "~user" can resolve into
"/home/user".

On Windows we do not have to worry about resolving this file.

Added an autotest for this as well.

M  +81   -18   autotests/knewfilemenutest.cpp
M  +21   -5    src/filewidgets/knewfilemenu.cpp

https://invent.kde.org/frameworks/kio/-/commit/26292d7d97d64c029424c5cf610053f2d8eb2e74