mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-05 06:26:49 +00:00
Escape problematic characters in VFS
With full-width <>:"\|?*
This commit is contained in:
parent
19f3bb8cb0
commit
5b19908996
5 changed files with 253 additions and 15 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#include "stdafx.h"
|
||||
#include "stdafx.h"
|
||||
#include "IdManager.h"
|
||||
#include "VFS.h"
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ std::string vfs::get(const std::string& vpath, vfs::type _type)
|
|||
return {};
|
||||
}
|
||||
|
||||
return found->second + vpath;
|
||||
return found->second + vfs::escape(vpath);
|
||||
}
|
||||
|
||||
if (_type == type::ps3 && match.length(1) == 0)
|
||||
|
|
@ -58,6 +58,231 @@ std::string vfs::get(const std::string& vpath, vfs::type _type)
|
|||
return {};
|
||||
}
|
||||
|
||||
// Concatenate
|
||||
return found->second + match.str(2);
|
||||
if (found->second.empty())
|
||||
{
|
||||
// Don't escape /host_root (TODO)
|
||||
return match.str(2);
|
||||
}
|
||||
|
||||
// Escape and concatenate
|
||||
return found->second + vfs::escape(match.str(2));
|
||||
}
|
||||
|
||||
|
||||
std::string vfs::escape(const std::string& path)
|
||||
{
|
||||
std::string result;
|
||||
result.reserve(path.size());
|
||||
|
||||
for (std::size_t i = 0, s = path.size(); i < s; i++)
|
||||
{
|
||||
switch (char c = path[i])
|
||||
{
|
||||
case '<':
|
||||
{
|
||||
result += u8"<";
|
||||
break;
|
||||
}
|
||||
case '>':
|
||||
{
|
||||
result += u8">";
|
||||
break;
|
||||
}
|
||||
case ':':
|
||||
{
|
||||
result += u8":";
|
||||
break;
|
||||
}
|
||||
case '"':
|
||||
{
|
||||
result += u8""";
|
||||
break;
|
||||
}
|
||||
case '\\':
|
||||
{
|
||||
result += u8"\";
|
||||
break;
|
||||
}
|
||||
case '|':
|
||||
{
|
||||
result += u8"|";
|
||||
break;
|
||||
}
|
||||
case '?':
|
||||
{
|
||||
result += u8"?";
|
||||
break;
|
||||
}
|
||||
case '*':
|
||||
{
|
||||
result += u8"*";
|
||||
break;
|
||||
}
|
||||
case char{u8"!"[0]}:
|
||||
{
|
||||
// Escape full-width characters 0xFF01..0xFF5e with ! (0xFF01)
|
||||
switch (path[i + 1])
|
||||
{
|
||||
case char{u8"!"[1]}:
|
||||
{
|
||||
const uchar c3 = reinterpret_cast<const uchar&>(path[i + 2]);
|
||||
|
||||
if (c3 >= 0x81 && c3 <= 0xbf)
|
||||
{
|
||||
result += u8"!";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case char{u8"`"[1]}:
|
||||
{
|
||||
const uchar c3 = reinterpret_cast<const uchar&>(path[i + 2]);
|
||||
|
||||
if (c3 >= 0x80 && c3 <= 0x9e)
|
||||
{
|
||||
result += u8"!";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
result += c;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
result += c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string vfs::unescape(const std::string& path)
|
||||
{
|
||||
std::string result;
|
||||
result.reserve(path.size());
|
||||
|
||||
for (std::size_t i = 0, s = path.size(); i < s; i++)
|
||||
{
|
||||
switch (char c = path[i])
|
||||
{
|
||||
case char{u8"!"[0]}:
|
||||
{
|
||||
switch (path[i + 1])
|
||||
{
|
||||
case char{u8"!"[1]}:
|
||||
{
|
||||
const uchar c3 = reinterpret_cast<const uchar&>(path[i + 2]);
|
||||
|
||||
if (c3 >= 0x81 && c3 <= 0xbf)
|
||||
{
|
||||
switch (path[i + 2])
|
||||
{
|
||||
case char{u8"!"[2]}:
|
||||
{
|
||||
i += 3;
|
||||
result += c;
|
||||
continue;
|
||||
}
|
||||
case char{u8"<"[2]}:
|
||||
{
|
||||
result += '<';
|
||||
break;
|
||||
}
|
||||
case char{u8">"[2]}:
|
||||
{
|
||||
result += '>';
|
||||
break;
|
||||
}
|
||||
case char{u8":"[2]}:
|
||||
{
|
||||
result += ':';
|
||||
break;
|
||||
}
|
||||
case char{u8"""[2]}:
|
||||
{
|
||||
result += '"';
|
||||
break;
|
||||
}
|
||||
case char{u8"\"[2]}:
|
||||
{
|
||||
result += '\\';
|
||||
break;
|
||||
}
|
||||
case char{u8"?"[2]}:
|
||||
{
|
||||
result += '?';
|
||||
break;
|
||||
}
|
||||
case char{u8"*"[2]}:
|
||||
{
|
||||
result += '*';
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Unrecognized character (ignored)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
i += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += c;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case char{u8"`"[1]}:
|
||||
{
|
||||
const uchar c3 = reinterpret_cast<const uchar&>(path[i + 2]);
|
||||
|
||||
if (c3 >= 0x80 && c3 <= 0x9e)
|
||||
{
|
||||
switch (path[i + 2])
|
||||
{
|
||||
case char{u8"|"[2]}:
|
||||
{
|
||||
result += '|';
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Unrecognized character (ignored)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
i += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += c;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
result += c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
result += c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue