# Linux, spaces in path, startAsProcess and Process::openDocument

**URL:** <https://forum.juce.com/t/linux-spaces-in-path-startasprocess-and-process-opendocument/47296>\
**Category:** Linux\
**Created:** [August 11, 2021, 12:58pm UTC](https://forum.juce.com/t/linux-spaces-in-path-startasprocess-and-process-opendocument/47296 "2021-08-11T12:58:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![baconpaul](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/baconpaul/32/8403_2.png) [@baconpaul](https://forum.juce.com/u/baconpaul)\
**Post date:** [August 11, 2021, 12:58pm UTC](https://forum.juce.com/t/linux-spaces-in-path-startasprocess-and-process-opendocument/47296/1 "2021-08-11T12:58:52Z")

</div>

Hi!

One of the features in surge is to let people open their user directory. Pretty straignt forward. We basically go

```auto
   auto path = juce::File( userDirStr );
   path.startAsProcess();

```

on mac and win this works fine and on linux it used to, but this weekend we changed the name of our user directory from `Surge` to `Surge XT`.

So now I get a directory which looks like `/home/paul/Documents/Surge XT` being passed to the above code. The path is correct but startAsProcess munges it.

The problem appears to be here:

```auto
bool Process::openDocument (const String& fileName, const String& parameters)
{
    auto cmdString = fileName.replace (" ", "\\ ", false);
    cmdString << " " << parameters;

```

that first line turns my directory into `Surge\ XT` and the subsequent commands into

```auto
xdg-open "/home/paul/Documents/Surge\ XT" || /etc/alternatives/x-www-browser "/home/paul/Documents/Surge\ XT" || firefox "/home/paul/Documents/Surge\ XT" || mozilla "/home/paul/Documents/Surge\ XT" || google-chrome "/home/paul/Documents/Surge\ XT" || chromium-browser "/home/paul/Documents/Surge\ XT" || opera "/home/paul/Documents/Surge\ XT" || konqueror "/home/paul/Documents/Surge\ XT"

```

note the `\ ` inside the `"`. So this double protects the space. This is because you use cmdString.quoted() to construct the array inside the if area.

This patch fixed it for me but I’m not sure if it is what you want.

Thanks for any thoughts!

```auto
diff --git a/modules/juce_core/native/juce_linux_Files.cpp b/modules/juce_core/native/juce_linux_Files.cpp
index 99893aaa0..1f946fd0f 100644
--- a/modules/juce_core/native/juce_linux_Files.cpp
+++ b/modules/juce_core/native/juce_linux_Files.cpp
@@ -208,6 +208,15 @@ bool Process::openDocument (const String& fileName, const String& parameters)
     {
         StringArray cmdLines;
 
+ /*
+ * since we are quoting the cmdstring with .quoted() when building
+ * the compound command line below, we can remove the space protection
+ * since that would double-protect filenames with spaces in them.
+ *
+ * Note that arguments will make this dicey .. but in multiple ways anyway
+ */
+ cmdString = fileName;
+
         for (auto browserName : { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla",
                                   "google-chrome", "chromium-browser", "opera", "konqueror" })
         {

```

---

<div class="post-metadata">

**Author:** ![baconpaul](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/baconpaul/32/8403_2.png) [@baconpaul](https://forum.juce.com/u/baconpaul)\
**Post date:** [August 20, 2021, 5:50pm UTC](https://forum.juce.com/t/linux-spaces-in-path-startasprocess-and-process-opendocument/47296/2 "2021-08-20T17:50:43Z")

</div>

hi! Just a quick bump on this. I can work around it by merging an xdg-open myself but if it was fixable for 6.1 that would be lovely! Thanks so much.

---

<div class="post-metadata">

**Author:** ![jpo](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jpo/32/503_2.png) [@jpo](https://forum.juce.com/u/jpo)\
**Post date:** [August 21, 2021, 12:59pm UTC](https://forum.juce.com/t/linux-spaces-in-path-startasprocess-and-process-opendocument/47296/3 "2021-08-21T12:59:15Z")

</div>

JUCE would probably benefit from a proper shellquote function for this kind of stuff, as escaping whitespaces and quoting arguments is not a full-proof protection against crafted arguments that could trigger execution of an arbitrary process

---

<div class="post-metadata">

**Author:** ![baconpaul](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/baconpaul/32/8403_2.png) [@baconpaul](https://forum.juce.com/u/baconpaul)\
**Post date:** [August 21, 2021, 1:40pm UTC](https://forum.juce.com/t/linux-spaces-in-path-startasprocess-and-process-opendocument/47296/4 "2021-08-21T13:40:27Z")

</div>

I agree with that; but right now am experiencing the fact that it incorrectly double protects even with the simple protection it does

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [September 23, 2021, 12:55pm UTC](https://forum.juce.com/t/linux-spaces-in-path-startasprocess-and-process-opendocument/47296/5 "2021-09-23T12:55:43Z")

</div>

Thanks for your patience. I’ve merged a fix here:

> <https://github.com/juce-framework/JUCE/commit/d738f0274ef5cbb438ddf5fc8105082818038d29>
>
> The previous implementation would fail to open directories with names
> that conta…ined 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.

Please let us know if you encounter any problems with this change.

---

<div class="post-metadata">

**Author:** ![baconpaul](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/baconpaul/32/8403_2.png) [@baconpaul](https://forum.juce.com/u/baconpaul)\
**Post date:** [September 23, 2021, 2:43pm UTC](https://forum.juce.com/t/linux-spaces-in-path-startasprocess-and-process-opendocument/47296/6 "2021-09-23T14:43:16Z")

</div>

Thank you!!
