mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-15 00:24:19 +00:00
The File class will now canonicalise the paths that it is given, to remove ellipsis
This commit is contained in:
parent
606e7be12f
commit
f6dd015999
1 changed files with 23 additions and 1 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue