Don't accept a trailing dot from native save dialogs - #122725
Open
AdrienUfferte wants to merge 1 commit into
Open
Don't accept a trailing dot from native save dialogs#122725AdrienUfferte wants to merge 1 commit into
AdrienUfferte wants to merge 1 commit into
Conversation
KDE's "Automatically select filename extension" can append a bare "." to the chosen file name when the selected filter carries no usable extension (KDE bug 501085, fixed in KIO 6.13). FileDialog emitted that path as-is. A file name ending in a bare dot has no extension, so ResourceSaver then refuses to write it and the save silently fails behind a warning. This is the same class of defect as the macOS extension handling fixed in godotengine#113757 and godotengine#114781, and is guarded the same way: in Godot, not in the OS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disclaimer: AI helped me find the root cause, check that Godot had no existing issue or PR for it, and write this description.
What problem(s) does this PR solve?
With the KDE portal, a native save dialog can return a name ending in a bare dot —
new_asset_2.res.. Such a name has no extension, soResourceSaverrefuses to write it and the save silently fails behind a warning (hit on a mesh'ssave_to_file/pathin Advanced Import Settings):The dot is KDE's, not Godot's: for
application/octet-stream, KIO'sKFileWidgetauto-selected a single"."as the extension when the typed name carried no suffix it recognised —.resis not one, hence the dot afternew_asset_2.resin the repro below. Present in KIO 6.12.0, removed in 6.13.0 (KDE bug 501085, commit a7be926869d8). Godot sends;application/octet-streamforAll Files (*.*)since #99350, so this affects Godot >= 4.4 on KIO < 6.13.Godot then emits the name verbatim:
All Files (*.*)is the last filter entry, so_native_dialog_cb_with_optionstakes itsvalid = true; // Match none.branch.Same class as the macOS fixes #113757 and #114781, handled in
platform/macos/*rather than left to the OS. Normalising a name Godot is handed also keeps this independent of the user's KIO version.No issue opened, given the size of the fix.
Additional information
The 4 lines strip one trailing dot at the top of the
FILE_MODE_SAVE_FILEbranch and re-syncfilename_edit, as the extension-append path just below already does. Doing it at the top also feeds that path a clean name: previously a returnedfoo.under a*.resfilter becamefoo..res.Nothing intentional is lost, because KIO treats a trailing dot the same way —
appendExtension()strips it, soREADME.saves asREADME, and its comment tells you to typeREADME..if you really want the dot. The bug is that this check runs on the name as typed, so a dot KIO appends itself escapes it.Glad to move the guard to
platform/linuxbsd/freedesktop_portal_desktop.cpp(the placement matching the macOS fixes), or to stop sendingapplication/octet-streamfor theAll Files (*.*)entry instead, if either is preferred.Reproducer — needs a Plasma session on
xdg-desktop-portal-kdewith KIO < 6.13 and a target file that does not exist yet (appendExtension()early-returns when it does):Select
All Files (*.*), typenew_asset_2.res, Save.Before:
[/.../new_asset_2.res.]— after:[/.../new_asset_2.res]Here are the screenshots of how it happens: