concatPaths: process empty path1 correctly
ClosedPublic

Authored by aleksejshilin on Apr 24 2018, 9:19 AM.

Details

Summary

When path1 was empty (i.e. 'current directory'), concatPaths() used to
return an absolute path /path2 instead of just path2, which broke e.g.
KUrlCompletion in certain cases.

This commit makes concatPaths() return just path2 if path1 is empty.

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.
aleksejshilin created this revision.Apr 24 2018, 9:19 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptApr 24 2018, 9:19 AM
aleksejshilin requested review of this revision.Apr 24 2018, 9:19 AM
aleksejshilin planned changes to this revision.
aleksejshilin requested review of this revision.Apr 24 2018, 9:32 AM

Here is an example of KUrlCompletion breakage.
Before, it returned invalid absolute paths like /Desktop etc.:


After:

anthonyfieroni added a comment.EditedApr 24 2018, 12:00 PM

path1 *should* never be empty. Path2 is relative to it.

aleksejshilin added a comment.EditedApr 24 2018, 12:40 PM

path1 *should* never be empty

Hm... I thought concatPaths() is supposed to be used like this: concatPaths(basePath, relativePath) - then an empty basePath makes sense (and means 'current directory', like in $ cd Desktop). If this is not the case, then:

  • KUrlCompletion (and probably KCompletion) needs to be fixed;
  • Q_ASSERT(!path1.isEmpty()) should be added here so that such bugs get noticed.

Is this correct?

anthonyfieroni added a comment.EditedApr 24 2018, 1:28 PM

Q_ASSERT(!path2.startsWith(QLatin1Char('/')));

If path1 is empty path2 will point to full path not absolute e.g. /something it should be ./something.
// Edit: Misreading, path1 can be empty, so you are right.
+1 from me.

dfaure accepted this revision.Apr 28 2018, 10:05 AM

OK, so concatPaths returns absolute paths if path1 is absolute, and relative paths if path1 is relative. Makes sense, but should be documented.

This revision is now accepted and ready to land.Apr 28 2018, 10:05 AM
This revision was automatically updated to reflect the committed changes.