From bbee942645849e0075f2226a1ffe5d727aaaf8a0 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 28 Jan 2016 10:58:52 +0000 Subject: [PATCH] Made File::getChildFile handle paths containing double-slashes --- modules/juce_core/files/juce_File.cpp | 39 ++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/modules/juce_core/files/juce_File.cpp b/modules/juce_core/files/juce_File.cpp index a990e1764c..ad2d3c0dcd 100644 --- a/modules/juce_core/files/juce_File.cpp +++ b/modules/juce_core/files/juce_File.cpp @@ -379,27 +379,26 @@ bool File::isAbsolutePath (StringRef path) File File::getChildFile (StringRef relativePath) const { - if (isAbsolutePath (relativePath)) - return File (String (relativePath.text)); + String::CharPointerType r = relativePath.text; - if (relativePath[0] != '.') - return File (addTrailingSeparator (fullPath) + relativePath); + if (isAbsolutePath (r)) + return File (String (r)); + + #if JUCE_WINDOWS + if (r.indexOf ((juce_wchar) '/') >= 0) + return getChildFile (String (r).replaceCharacter ('/', '\\')); + #endif String path (fullPath); - // It's relative, so remove any ../ or ./ bits at the start.. - #if JUCE_WINDOWS - if (relativePath.text.indexOf ((juce_wchar) '/') >= 0) - return getChildFile (String (relativePath.text).replaceCharacter ('/', '\\')); - #endif - - while (relativePath[0] == '.') + while (*r == '.') { - const juce_wchar secondChar = relativePath[1]; + ++r; + const juce_wchar secondChar = r.getAndAdvance(); - if (secondChar == '.') + if (secondChar == '.') // remove "../" { - const juce_wchar thirdChar = relativePath[2]; + const juce_wchar thirdChar = r.getAndAdvance(); if (thirdChar == 0 || thirdChar == separator) { @@ -407,16 +406,18 @@ File File::getChildFile (StringRef relativePath) const if (lastSlash >= 0) path = path.substring (0, lastSlash); - relativePath = relativePath.text + (thirdChar == 0 ? 2 : 3); + while (*r == separator) // ignore duplicate slashes + ++r; } else { break; } } - else if (secondChar == separator) + else if (secondChar == separator) // remove "./" { - relativePath = relativePath.text + 2; + while (*r == separator) // ignore duplicate slashes + ++r; } else { @@ -424,7 +425,9 @@ File File::getChildFile (StringRef relativePath) const } } - return File (addTrailingSeparator (path) + relativePath); + path = addTrailingSeparator (path); + path.appendCharPointer (r); + return File (path); } File File::getSiblingFile (StringRef fileName) const