mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
File: Fix quoting in openDocument() on Linux
The previous implementation would fail to open directories with names that contained spaces, as the space would be escaped and then quoted. I don't think it's particularly meaningful to supply parameters when opening a file in this way (especially not quoting the parameters too!) so I've removed that functionality.
This commit is contained in:
parent
9199fa3c51
commit
d738f0274e
1 changed files with 19 additions and 15 deletions
|
|
@ -199,27 +199,31 @@ static bool isFileExecutable (const String& filename)
|
|||
|
||||
bool Process::openDocument (const String& fileName, const String& parameters)
|
||||
{
|
||||
auto cmdString = fileName.replace (" ", "\\ ", false);
|
||||
cmdString << " " << parameters;
|
||||
|
||||
if (cmdString.startsWithIgnoreCase ("file:")
|
||||
|| File::createFileWithoutCheckingPath (fileName).isDirectory()
|
||||
|| ! isFileExecutable (fileName))
|
||||
const auto cmdString = [&]
|
||||
{
|
||||
StringArray cmdLines;
|
||||
|
||||
for (auto browserName : { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla",
|
||||
"google-chrome", "chromium-browser", "opera", "konqueror" })
|
||||
if (fileName.startsWithIgnoreCase ("file:")
|
||||
|| File::createFileWithoutCheckingPath (fileName).isDirectory()
|
||||
|| ! isFileExecutable (fileName))
|
||||
{
|
||||
cmdLines.add (String (browserName) + " " + cmdString.trim().quoted());
|
||||
const auto singleCommand = fileName.trim().quoted();
|
||||
|
||||
StringArray cmdLines;
|
||||
|
||||
for (auto browserName : { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla",
|
||||
"google-chrome", "chromium-browser", "opera", "konqueror" })
|
||||
{
|
||||
cmdLines.add (String (browserName) + " " + singleCommand);
|
||||
}
|
||||
|
||||
return cmdLines.joinIntoString (" || ");
|
||||
}
|
||||
|
||||
cmdString = cmdLines.joinIntoString (" || ");
|
||||
}
|
||||
return (fileName.replace (" ", "\\ ", false) + " " + parameters).trim();
|
||||
}();
|
||||
|
||||
const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), nullptr };
|
||||
const char* const argv[] = { "/bin/sh", "-c", cmdString.toUTF8(), nullptr };
|
||||
|
||||
auto cpid = fork();
|
||||
const auto cpid = fork();
|
||||
|
||||
if (cpid == 0)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue