From 0c756ef71f5eca1013365729098f78c3f5dafc78 Mon Sep 17 00:00:00 2001 From: Tres Finocchiaro Date: Sat, 3 Mar 2018 22:46:07 -0500 Subject: [PATCH] Use Canonical Paths for Relative Paths Calculations (#4211) Fix redundant path elements Closes #4173 --- src/core/ConfigManager.cpp | 4 ++-- src/core/SampleBuffer.cpp | 3 ++- tests/src/core/RelativePathsTest.cpp | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/ConfigManager.cpp b/src/core/ConfigManager.cpp index 734ccb80e46..a99223a9d41 100644 --- a/src/core/ConfigManager.cpp +++ b/src/core/ConfigManager.cpp @@ -225,9 +225,9 @@ bool ConfigManager::hasWorkingDir() const } -void ConfigManager::setWorkingDir( const QString & _wd ) +void ConfigManager::setWorkingDir( const QString & wd ) { - m_workingDir = ensureTrailingSlash( _wd ); + m_workingDir = ensureTrailingSlash( QFileInfo( wd ).canonicalFilePath() ); } diff --git a/src/core/SampleBuffer.cpp b/src/core/SampleBuffer.cpp index cb930b08789..141085dd2d9 100644 --- a/src/core/SampleBuffer.cpp +++ b/src/core/SampleBuffer.cpp @@ -1415,7 +1415,8 @@ QString SampleBuffer::tryToMakeRelative( const QString & file ) { if( QFileInfo( file ).isRelative() == false ) { - QString f = QString( file ).replace( QDir::separator(), '/' ); + // Normalize the path + QString f = QFileInfo( file ).canonicalFilePath().replace( QDir::separator(), '/' ); // First, look in factory samples // Isolate "samples/" from "data:/samples/" diff --git a/tests/src/core/RelativePathsTest.cpp b/tests/src/core/RelativePathsTest.cpp index 555fa39b56a..6a75483776a 100644 --- a/tests/src/core/RelativePathsTest.cpp +++ b/tests/src/core/RelativePathsTest.cpp @@ -40,8 +40,11 @@ private slots: QString absPath = fi.absoluteFilePath(); QString relPath = "drums/kick01.ogg"; + QString fuzPath = absPath; + fuzPath.replace(relPath, "drums/.///kick01.ogg"); QCOMPARE(SampleBuffer::tryToMakeRelative(absPath), relPath); QCOMPARE(SampleBuffer::tryToMakeAbsolute(relPath), absPath); + QCOMPARE(SampleBuffer::tryToMakeRelative(fuzPath), relPath); } } RelativePathTests;