Skip to content

Commit

Permalink
Use Canonical Paths for Relative Paths Calculations (#4211)
Browse files Browse the repository at this point in the history
Fix redundant path elements
Closes #4173
  • Loading branch information
tresf committed Mar 4, 2018
1 parent 926b654 commit 1d63bd3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core/ConfigManager.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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() );
} }




Expand Down
3 changes: 2 additions & 1 deletion src/core/SampleBuffer.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1415,7 +1415,8 @@ QString SampleBuffer::tryToMakeRelative( const QString & file )
{ {
if( QFileInfo( file ).isRelative() == false ) 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 // First, look in factory samples
// Isolate "samples/" from "data:/samples/" // Isolate "samples/" from "data:/samples/"
Expand Down
3 changes: 3 additions & 0 deletions tests/src/core/RelativePathsTest.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ private slots:


QString absPath = fi.absoluteFilePath(); QString absPath = fi.absoluteFilePath();
QString relPath = "drums/kick01.ogg"; QString relPath = "drums/kick01.ogg";
QString fuzPath = absPath;
fuzPath.replace(relPath, "drums/.///kick01.ogg");
QCOMPARE(SampleBuffer::tryToMakeRelative(absPath), relPath); QCOMPARE(SampleBuffer::tryToMakeRelative(absPath), relPath);
QCOMPARE(SampleBuffer::tryToMakeAbsolute(relPath), absPath); QCOMPARE(SampleBuffer::tryToMakeAbsolute(relPath), absPath);
QCOMPARE(SampleBuffer::tryToMakeRelative(fuzPath), relPath);
} }
} RelativePathTests; } RelativePathTests;


Expand Down

0 comments on commit 1d63bd3

Please sign in to comment.