Skip to content

Remove validation check for old file path during rename#23871

Open
bwrightkc wants to merge 2 commits intoqbittorrent:masterfrom
bwrightkc:master
Open

Remove validation check for old file path during rename#23871
bwrightkc wants to merge 2 commits intoqbittorrent:masterfrom
bwrightkc:master

Conversation

@bwrightkc
Copy link

@bwrightkc bwrightkc commented Feb 23, 2026

Closes #23834.

What: Remove validation check for old file path during rename.

Why: The previous validation prevented renaming files whose existing
paths contained disallowed characters (e.g., ":" on macOS).
This made it impossible to rename files specifically because
their current names were invalid.

Removing this check allows invalid filenames and folder names
to be corrected.

Tested on: macOS, Windows 11.

remove check for validity of old file path - causes issue where disallowed character (ex colon on macOS) cannot be renamed as the file path would be "invalid", which is a main reason one may need to rename that filename.
@glassez
Copy link
Member

glassez commented Feb 24, 2026

The previous validation prevented renaming files whose existing
paths contained disallowed characters (e.g., ":" on macOS).

I wonder how such a torrent can appear at all? As far as I know, libtorrent cleans inappropriate paths when adding a torrent. Are you saying that it doesn't work in some cases?

Tested on: macOS, Windows 11.

How did you test it on Windows? Do you have some kind of .torrent file that contains invalid characters in the file paths? Then could you provide it for testing?

@bwrightkc
Copy link
Author

The previous validation prevented renaming files whose existing
paths contained disallowed characters (e.g., ":" on macOS).
I wonder how such a torrent can appear at all? As far as I know, libtorrent cleans inappropriate paths when adding a torrent. Are you saying that it doesn't work in some cases?

Good question, looking at it it doesn't seem like libtorrent cleans filenames on Linux or macOS looking in torrent_info.cpp at line 93

#ifdef TORRENT_WINDOWS
		// On windows, both the filesystem and the operating system impose
		// restrictions.
		static const char invalid_chars[] = "?<>\"|\b*:";
#elif defined TORRENT_ANDROID
		// The Android kernel probably has similar restrictions as Linux (i.e.
		// very few) but it appears some user-space system libraries impose
		// additional restrictions, and it's probably more common to use FAT32
		// style filesystems, which also further restricts valid characters
		// https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/os/FileUtils.java;l=997?q=isValidFatFilenameChar
		static const char invalid_chars[] = "\"*:<>?|";
#else
		static const char invalid_chars[] = "";

Probably worth fixing in both qBittorrent and libtorrent (I'm going to take a closer look at that today as it might be smart to filter out /: on the libtorrent end to prevent any macOS issues there).

However, on the qBittorrent end, I think it's just simple enough to allow the user to rename the file regardless of any invalid characters in the name.

How did you test it on Windows? Do you have some kind of .torrent file that contains invalid characters in the file paths? Then could you provide it for testing?

Apologies, I shouldn't have put Windows - I compiled with the patch on Windows to verify that I didn't break anything, but the issue I was only able to recreate on macOS.

@xavier2k6
Copy link
Member

xref: #23386

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cannot rename file with illegal character, either when adding torrent or after adding torrent

3 participants