replaceIllegalCharacters doesn't handle illegal filename
A system-wide equalizer for Windows 7 / 8 / 8.1 / 10 / 11
Brought to you by:
jthedering
StringHelper::replaceIllegalCharacters() currently replaces only the standard Windows filename characters:
wstring StringHelper::replaceIllegalCharacters(const wstring& filename)
{
return replaceCharacters(filename, L"<>:\"/\\|?*", L"_");
}
However, it does not remove ASCII control characters (e.g. \r, \n, \t).
On my system, the Bluetooth audio endpoint property ({b3f8fa53-0004-438e-9003-51a46e139bfc},6) contains a trailing CRLF:
20 50 65 62 62 6C 65 20 56 33 0D 0A
which corresponds to:
" Pebble V3\r\n"
When DeviceSelector generates the backup filename:
L"backup_" +
StringHelper::replaceIllegalCharacters(deviceName) +
L"_" +
StringHelper::replaceIllegalCharacters(connectionName) +
L".reg"
the control characters are preserved, resulting in an invalid filename and the following error:
Error while opening file backup_ Pebble V3 _Headphones.reg for writing
A possible fix is to strip ASCII control characters before replacing the standard Windows filename characters:
wstring StringHelper::replaceIllegalCharacters(const wstring& filename)
{
wstring sanitized;
for (wchar_t c : filename)
{
if (c < 32)
continue;
sanitized += c;
}
return replaceCharacters(sanitized, L"<>:\"/\\|?*", L"_");
}