Bug 382242 - Deprecated hint for KUrl::path() is wrong on Windows
Summary: Deprecated hint for KUrl::path() is wrong on Windows
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kdelibs4support
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.36.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: kdelibs bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-11 14:37 UTC by Ralf Habacker
Modified: 2017-07-14 11:20 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 5.37
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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