Change an assert to do as the function documentation tells
ClosedPublic

Authored by jtamate on Jan 24 2018, 11:34 AM.

Details

Summary

Instead of an assert do as the documentation tells: return an invalid Url.

  • In case both URLs are equal, an invalid URL is returned
Test Plan

How to assert:
In dolphin, in the location bar, change it into text and enter into one level directory from root, for example /d
When it changes into the breadcrum, press into the root one and crash (in Debug build).

I've been using this patch one month. And it doesn't affect the unit tests.

Diff Detail

Repository
R241 KIO
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
jtamate created this revision.Jan 24 2018, 11:34 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptJan 24 2018, 11:34 AM
jtamate requested review of this revision.Jan 24 2018, 11:34 AM

IIRC this method is unittested, right? Please extend the unittest.

jtamate updated this revision to Diff 25872.Jan 24 2018, 12:14 PM
jtamate edited the test plan for this revision. (Show Details)

Added more unit tests with some comments.

dfaure requested changes to this revision.Jan 24 2018, 12:26 PM

Strange that the "bug report" mentions /d but the unittests doesn't have anything like that.

In fact, is it just me, or does the "extended" unittest pass without the fix? My testing seems to indicate that.

A good unittest for a bugfix has to *fail* without the fix applied ;)

This revision now requires changes to proceed.Jan 24 2018, 12:26 PM
jtamate updated this revision to Diff 25883.Jan 24 2018, 2:10 PM

Do the right thing in the case of urls that end in / after the slash stripping.

This new test fails without the patch.
QCOMPARE(KIO::UrlUtil::firstChildUrl(lUrl("/d"), lUrl("/")), lUrl("/d"));

Heh, see the point of writing unittests that actually test the bug ;) It lead to a different fix so it was clearly useful ;)

src/filewidgets/urlutil_p.h
69

s/S/s/ twice

You could also just use adjustedCurrentUrl.path(QUrl::StripTrailingSlash), no?
Then you wouldn't have to deal with the fact that the path might end with a slash
(and it would also cover the case where it ends with two or more consecutive slashes....)

jtamate updated this revision to Diff 25890.Jan 24 2018, 3:38 PM
jtamate marked an inline comment as done.

replaced two uppercase S

src/filewidgets/urlutil_p.h
69

It is already done (it's a pity that this can't be seen creating the patch using the web):

const QUrl adjustedLastUrl = lastUrl.adjusted(QUrl::StripTrailingSlash);
const QUrl adjustedCurrentUrl = currentUrl.adjusted(QUrl::StripTrailingSlash);

but in the case of the new test, the values are:
"/d" and "/" from the originals: "file:///d" and "file:///"

dfaure accepted this revision.Jan 24 2018, 4:51 PM

Ah, OK (yes, this is why you should use arc diff to upload patches...) :-)

This revision is now accepted and ready to land.Jan 24 2018, 4:51 PM

Actually, maybe parentPath == "/" would be more readable then, otherwise the next reader will wonder, how it can end with a slash after StripTrailingSlash was used...

jtamate updated this revision to Diff 25907.Jan 24 2018, 6:56 PM
jtamate edited the summary of this revision. (Show Details)

Improved, in my opinion, one comment.

dfaure accepted this revision.Jan 25 2018, 6:37 PM
This revision was automatically updated to reflect the committed changes.