1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-25 02:04:23 +00:00

Made File::getChildFile handle paths containing double-slashes

This commit is contained in:
jules 2016-01-28 10:58:52 +00:00
parent 101c4782e1
commit bbee942645

View file

@ -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