Bug 185433

Summary: Open/save dialog cannot open or save filenames containing double quotes
Product: [Frameworks and Libraries] frameworks-kio Reporter: Inge Wallin <inge>
Component: Open/save dialogsAssignee: Andreas Bontozoglou <a.bontozoglou>
Severity: major CC: a.bontozoglou, adaptee, adawit, arthur, benhuan, brendon, bugseforuns, bugzilla.kde, chshu, ereslibre, faure, glyphimor, grosser.meister.morti, hessijames, kdelibs-bugs, kdespam34fb987, lukasz.wojnilowicz, mail, nate, pascal, stharward, walch.martin
Priority: VHI Keywords: testcase, usability
Version: 5.45.0   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Unspecified   
See Also: https://bugs.kde.org/show_bug.cgi?id=426728
Latest Commit: Version Fixed In:

Description Inge Wallin 2009-02-24 13:31:50 UTC
Version:            (using KDE 4.2.0)
Installed from:    Compiled From Sources

How to reproduce:

1. Create a file named "foo.txt", including the double quotes.
2. Start kword or possibly any other editor like kate.
   This bug was discovered with kword 2.0beta6
3. Choose File -> Open in the dialog.
4. Open the file

You will get an error message saying the file doesn't exist.
Comment 1 David Faure 2009-02-24 13:36:45 UTC
Yes, happens with kwrite too. Must be the code for multi-selecting files ("a.txt "b.txt"), which removes double-quotes automatically.
Comment 2 Christoph Feck 2009-10-25 17:04:09 UTC
*** Bug 211739 has been marked as a duplicate of this bug. ***
Comment 3 Christoph Feck 2010-10-12 17:40:40 UTC
*** Bug 218194 has been marked as a duplicate of this bug. ***
Comment 4 Christoph Feck 2012-10-24 20:46:42 UTC
*** Bug 308277 has been marked as a duplicate of this bug. ***
Comment 5 Soren Harward 2012-11-20 17:04:12 UTC
I ran into this bug with Amarok.  It's not just multi-select.  It's that when the dialog's selectedUrls() function is called, the URL being returned contains only the portion of the filename that's within the quotes.  So if I had the files:


calling KFileDialog::selectedUrls() would return

Comment 6 Dawit Alemayehu 2013-06-18 04:56:59 UTC
*** Bug 189935 has been marked as a duplicate of this bug. ***
Comment 7 Dawit Alemayehu 2013-06-18 04:59:17 UTC
Someone needs to fix KFileWidget (kdelibs/kfile/kfilewidget.cpp)... Line #1641 at contains the following statement:

             // FIXME: current implementation drawback: a filename can't contain quotes

 Unless that is resolved this problem will remain.
Comment 8 Daniel Faust 2013-09-07 09:00:31 UTC
The multi-selection code seems to be a problem in general. E. g. selecting files containing percent signs only works in single-selection mode. Meaning there are two code paths which is bad for testing.

If a filename contains double quotes, it is falsely detected as a multi-selection string and everything outside of the quotes gets ignored.
Comment 9 Francis Herne 2016-05-03 21:20:37 UTC
This is more serious than it says on the tin.

It affects _saving_ files too...save to FooDoc("quotes").file, and pretty much every KDE app will write to 'quotes'.

Best-case, the file isn't saved to where the user expected it but they notice.
Worse, it's saved somewhere else and they think they've lost all their work.

At least there's a popup before clobbering 'quotes' if it exists, but people aren't good at paying attention to those.
Comment 10 Francis Herne 2017-03-11 03:57:37 UTC
*** Bug 362613 has been marked as a duplicate of this bug. ***
Comment 11 Nate Graham 2018-04-10 21:57:58 UTC
*** Bug 329258 has been marked as a duplicate of this bug. ***
Comment 12 realnobody 2018-04-12 19:31:59 UTC
#c8 mentions percent signs - there are also question marks which cause problems, see Bug 329259 ... possibly a related cause.
Comment 13 realnobody 2018-04-12 19:40:18 UTC
(In reply to realnobody from comment #12)
forget that, I just tried again - and it seems the mentioned "?" case if fixed in the meantime.
Comment 14 Nate Graham 2018-08-22 20:05:31 UTC
*** Bug 355821 has been marked as a duplicate of this bug. ***
Comment 15 Patrick Silva 2020-07-27 13:20:30 UTC
*** Bug 424702 has been marked as a duplicate of this bug. ***
Comment 16 Bug Janitor Service 2020-08-02 10:20:27 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/89
Comment 17 Andreas Bontozoglou 2020-08-02 10:24:26 UTC
Taking this over with an open MR - feel free to take back
Comment 18 Nate Graham 2020-08-02 13:34:30 UTC
Thanks for working on this, Andreas! Much appreciated.
Comment 19 David Faure 2020-09-12 18:04:00 UTC
Git commit 87adf7f6bcbd9baddafda58e2dbf7052eb323358 by David Faure, on behalf of Andreas Bontozoglou.
Committed on 12/09/2020 at 18:03.
Pushed by dfaure into branch 'master'.

[kio] BUG: Allowing double-quotes in open/save dialog

tl;dr: Allowing double-quotes in filenames in KFileWidget by escaping them with `\` and modifying the tokenizer to understand this.

In this patch:

- Introduce `escapeDoubleQuotes` function that is used to escape selected file paths and correctly populate the `locationEdit`

- Disabling old KFileWidgetPrivate::tokenize and writing a new one which works by iterating each character in the `locationEdit` while it remembers if it is in "escape mode" (seen a '\') or not.

- Introducing **public API** `KFileWidget::setSelectedUrls`. This was mainly needed for the tests to work. I originally wanted to test only the tokenizer but (a) this is in private implementation and (b) testing that things are escaped properly in the text-box is also very important

- Adding a test for various filenames that contain a mix of backslashes and quotes

- Adding a new logging category for the kfilewidget.cpp (KIO_KFILEWIDGETS_FW)

- Adding command-line options to `kfilewidgettest_saving_gui` which I used for functional tests at some point. My work there is a bit sloppy atm but I assume this is an auxiliary file (let me now if you want me to clean it up)


- Do I need to add a @since in the docblock?

- Do I need to change minor/major version here (and how would I do this)? I am not sure if the addition of `setSelectedUrls` is backwards compatible

M  +105  -0    autotests/kfilewidgettest.cpp
M  +9    -0    src/filewidgets/CMakeLists.txt
M  +98   -46   src/filewidgets/kfilewidget.cpp
M  +8    -0    src/filewidgets/kfilewidget.h
M  +25   -7    tests/kfilewidgettest_saving_gui.cpp