Bug 378933

Summary: Deleting items with trailing whitespace in the projects view deletes something else
Product: [Applications] kdevelop Reporter: Petr Mrázek <peterix>
Component: file treeAssignee: kdevelop-bugs-null
Status: CONFIRMED ---    
Severity: normal CC: mail, software
Priority: HI    
Version First Reported In: 5.1.0   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Petr Mrázek 2017-04-18 20:40:38 UTC
For example:

If you have a file named ' ' (single space) in a folder, deleting the file will result in everything else in the folder being deleted.

Deleting 'foo ' when both 'foo' and 'foo ' exist will result in the deletion of 'foo'. Both 'foo' and 'foo ' disappear from the view until a refresh.
Comment 1 Kevin Funk 2017-04-19 08:08:37 UTC
Confirmed. That's... bad.
Comment 2 Kevin Funk 2017-04-19 08:16:25 UTC
There's another issue:

When removing " " inside $projectroot, KDevelop thinks that the whole project got removed and then closes the project:
  "The base folder of project X got deleted or moved outside of KDevelop. The project has to be closed."
Comment 3 Kevin Funk 2017-04-19 09:56:31 UTC
Git commit 080ed286fe100f7c736d5a77c587e0a1b9453882 by Kevin Funk.
Committed on 19/04/2017 at 09:56.
Pushed by kfunk into branch '5.1'.

Work-around issue in Path(QString) ctor

Problem: Path(QString) will call Path(QUrl) constructor, constructing an
url via QUrl::fromUserInput(...).

Because QUrl::fromUserInput by default is in tolerant mode, Path("/tmp/
") would be transformed into Path(QUrl("file:///tmp")) -> thus break the
path.

Consider this example:
```
 #include <QDebug>
 #include <QUrl>

int main()
{
    auto u1 = QUrl::fromLocalFile("/tmp/ ");
    auto u2 = QUrl::fromUserInput("/tmp/ ");
    qDebug() << u1.toLocalFile();
    qDebug() << u2.toLocalFile();
}
```

Will give:
```
main(8): "/tmp/ "
main(9): "/tmp/"
```

TODO: We need another Path ctor when we are sure we want to pass a local
file (e.g. by adding a static Path::fromLocalFile(...))?

M  +1    -1    project/abstractfilemanagerplugin.cpp

https://commits.kde.org/kdevplatform/080ed286fe100f7c736d5a77c587e0a1b9453882
Comment 4 Kevin Funk 2017-04-19 09:56:31 UTC
Git commit 76765692538d3af40374b0c9ae63eb6eb41c53c0 by Kevin Funk.
Committed on 19/04/2017 at 09:56.
Pushed by kfunk into branch '5.1'.

backgroundparser: Relax assert a bit

A file with just a space as file name is fine -- let's rather make sure
we don't pass a folder instead of a file as url

M  +1    -1    language/backgroundparser/backgroundparser.cpp

https://commits.kde.org/kdevplatform/76765692538d3af40374b0c9ae63eb6eb41c53c0
Comment 5 Kevin Funk 2017-04-19 09:56:51 UTC
Issue from comment #2 is fixed by 080ed286fe100f7c736d5a77c587e0a1b9453882
Comment 6 Santilin 2019-06-15 11:58:14 UTC
There are more issues with files ending in space. When I click on one of them in the file tree manager, it opens a new window file with the space trimmed. Then, I save it and it creates a new file with the ending space trimmed.