diff --git a/Deploy/distrostruct.cpp b/Deploy/distrostruct.cpp index e001ce5..ac2be39 100644 --- a/Deploy/distrostruct.cpp +++ b/Deploy/distrostruct.cpp @@ -58,10 +58,24 @@ void DistroStruct::setPluginsOutDir(const QString &value) { } QString DistroStruct::getRelativePath(QString path) const { - if (!path.size() || !(path[0] == "/" || path[0] == "\\")) - return ""; - int count = path.count(QRegExp("[\\/]")) - 1; + path.replace('\\', '/'); + + int index = -1; + do { + path.replace("//", "/"); + } while ((index = path.indexOf("//")) >= 0); + + if (path.left(1) != '/') { + path.insert(0, '/'); + } + + if (path.right(1) != '/') { + path.insert(path.size(), '/'); + } + + int count = path.count('/') - 1; + for (int i = 0; i < count; ++i) { path += "../"; } diff --git a/Deploy/distrostruct.h b/Deploy/distrostruct.h index c038695..857eb6d 100644 --- a/Deploy/distrostruct.h +++ b/Deploy/distrostruct.h @@ -41,6 +41,8 @@ public: void setResOutDeir(const QString &value); QString getPluginsOutDir(const QString& basePath = "/") const; void setPluginsOutDir(const QString &value); + + friend class deploytest; }; #endif // DISTROSTRUCT_H diff --git a/UnitTests/tst_deploytest.cpp b/UnitTests/tst_deploytest.cpp index 32c012b..1b68776 100644 --- a/UnitTests/tst_deploytest.cpp +++ b/UnitTests/tst_deploytest.cpp @@ -618,12 +618,33 @@ void deploytest::testDistroStruct() { DistroStruct distro; auto cases = QList>{ - {"", ""}, + {"", "/"}, {"/", "/"}, {"/res","/res/../"}, {"/res/","/res/../"}, - {"\\","\\"}, + {"/res/type","/res/type/../../"}, + {"/res/type/","/res/type/../../"}, + {"res/type","/res/type/../../"}, + {"res/type/","/res/type/../../"}, + {"res//type/","/res/type/../../"}, + {"res////type/","/res/type/../../"}, + {"//res///type/////","/res/type/../../"}, + {"\\", "/"}, + {"\\res","/res/../"}, + {"\\res\\","/res/../"}, + {"\\res\\type","/res/type/../../"}, + {"\\res\\type\\","/res/type/../../"}, + {"res\\type","/res/type/../../"}, + {"res\\type\\","/res/type/../../"}, + {"res\\\\type\\","/res/type/../../"}, + {"res\\\\\\\\type\\","/res/type/../../"}, + {"\\\\res\\\\\\type\\\\\\\\\\","/res/type/../../"}, }; + + for (auto &i: cases) { + QVERIFY(distro.getRelativePath(i.first) == i.second); + } + } void deploytest::mainTests() {