From f6dd015999a51fdca43fd87f8642a250dfbd145d Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 11 Jan 2016 14:59:30 +0000 Subject: [PATCH] The File class will now canonicalise the paths that it is given, to remove ellipsis --- modules/juce_core/files/juce_File.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/juce_core/files/juce_File.cpp b/modules/juce_core/files/juce_File.cpp index 9737fa8aad..a990e1764c 100644 --- a/modules/juce_core/files/juce_File.cpp +++ b/modules/juce_core/files/juce_File.cpp @@ -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)