Bug 382239

Summary: QUrl::path() returns invalid pathes on Windows
Product: [Applications] umbrello Reporter: Ralf Habacker <ralf.habacker>
Component: generalAssignee: Umbrello Development Group <umbrello-devel>
Status: RESOLVED FIXED    
Severity: normal CC: simonandric5
Priority: NOR    
Version: frameworks5   
Target Milestone: ---   
Platform: Other   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:
Bug Depends on:    
Bug Blocks: 373932    

Description Ralf Habacker 2017-07-11 13:55:43 UTC
On porting KUrl::path() references directly to QUrl::path() the related locations returns invalid file pathes on Windows as shown with following examples:

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

Running this code on Windows returns 

"/test/test.xyz" "/test/test.xyz"
"/c:/test/test.xyz" "c:/test/test.xyz"
"/c:/test/test.xyz" "c:/test/test.xyz"

line 2 and 3  column 1 shows that QUrl::path() always prefixes the path with '/' which is incorrect.

KUrl from KDE4 does not have this problem because it covers the "local file case" (see https://github.com/KDE/kdelibs/blob/KDE/4.14/kdecore/io/kurl.cpp#L873 for details).

Instead QUrl::toLocalFile() should be used, which is also safe to use on non Windows OS.
Comment 1 Ralf Habacker 2018-03-26 09:09:03 UTC
umbrello source code does not use QUrl::path() anymore.