Bug 382242

Summary: Deprecated hint for KUrl::path() is wrong on Windows
Product: [Frameworks and Libraries] frameworks-kdelibs4support Reporter: Ralf Habacker <ralf.habacker>
Component: generalAssignee: kdelibs bugs <kdelibs-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: simonandric5
Priority: NOR    
Version: 5.36.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 5.37
Sentry Crash Report:

Description Ralf Habacker 2017-07-11 14:37:39 UTC
At https://api.kde.org/frameworks/kdelibs4support/html/classKUrl.html#a04479511596e499f4f7ffa6acdc96cb3 there is documentated 

Deprecated:
    since 5.0, use QUrl::path(). ....

This advice results into code returning an invalid path on Windows in case QUrl contains a local path because QUrl::path() on Windows always adds a '/' in front of the path. 

The following example shows the issue 

    QUrl b = QUrl::fromLocalFile("/test/test.xyz");
    qDebug() << b << b.path() << b.toLocalFile();
    b = QUrl::fromLocalFile("c:/test/test.xyz");
    qDebug() << b << b.path() << b.toLocalFile();
    b = QUrl::fromLocalFile("c:\\test\\test.xyz");
    qDebug() << b << b.path() << b.toLocalFile() 

Compiling and running this on Windows (I used Qt 5.5) returns 

QUrl("file:///test/test.xyz") "/test/test.xyz" "/test/test.xyz"
QUrl("file:///c:/test/test.xyz") "/c:/test/test.xyz" "c:/test/test.xyz"
QUrl("file:///c:/test/test.xyz") "/c:/test/test.xyz" "c:/test/test.xyz"

The second column in line 2 and 3 shows the issue. 

Because KUrl::path() deals with this case by checking the "local file case" and using toLocalFile() instead porting to QUrl::path() directly will fail therefore.
Also the hint to use url.adjusted(QUrl::StripTrailingSlash).path() in case the option RemoveTrailingSlash has been used does not help here.

There should be a related hint into the documentation.
Comment 1 Ralf Habacker 2017-07-12 06:11:19 UTC
https://git.reviewboard.kde.org/r/130177/
Comment 2 Ralf Habacker 2017-07-14 11:20:29 UTC
Git commit 95a3a5c54518168d5b6ef38a7698b0cf6cdc647b by Ralf Habacker.
Committed on 14/07/2017 at 11:19.
Pushed by habacker into branch 'master'.

Fix 'Deprecated hint for KUrl::path() is wrong on Windows'
REVIEW:130177
FIXED-IN:5.37

M  +4    -2    src/kdecore/kurl.h

https://commits.kde.org/kdelibs4support/95a3a5c54518168d5b6ef38a7698b0cf6cdc647b