Browse Source

The File class will now canonicalise the paths that it is given, to remove ellipsis

tags/2021-05-28
jules 10 years ago
parent
commit
f6dd015999
1 changed files with 23 additions and 1 deletions
  1. +23
    -1
      modules/juce_core/files/juce_File.cpp

+ 23
- 1
modules/juce_core/files/juce_File.cpp View File

@@ -70,8 +70,24 @@ File& File::operator= (File&& other) noexcept
const File File::nonexistent;
//==============================================================================
static String removeEllipsis (const String& path)
{
StringArray toks;
toks.addTokens (path, File::separatorString, StringRef());
for (int i = 1; i < toks.size(); ++i)
{
if (toks[i] == ".." && toks[i - 1] != "..")
{
toks.removeRange (i - 1, 2);
i = jmax (0, i - 2);
}
}
return toks.joinIntoString (File::separatorString);
}
String File::parseAbsolutePath (const String& p)
{
if (p.isEmpty())
@@ -81,6 +97,9 @@ String File::parseAbsolutePath (const String& p)
// Windows..
String path (p.replaceCharacter ('/', '\\'));
if (path.contains ("\\..\\"))
path = removeEllipsis (path);
if (path.startsWithChar (separator))
{
if (path[1] != separator)
@@ -120,6 +139,9 @@ String File::parseAbsolutePath (const String& p)
String path (p);
if (path.contains ("/../"))
path = removeEllipsis (path);
if (path.startsWithChar ('~'))
{
if (path[1] == separator || path[1] == 0)


Loading…
Cancel
Save