BackstopJS icon indicating copy to clipboard operation
BackstopJS copied to clipboard

Remote fails if path contains space

Open BenceSzalai opened this issue 3 months ago • 2 comments

Title says it pretty much all.

I'm wondering if there is a reason for not wrapping the paths in "s when spawning the node process for the server?

It is easy to say not do put space in the path, but once a project is already initialised with many stuff already pointing at a folder it can be quite cumbersome to change folder names.

A fix could be as simple as changing https://github.com/garris/BackstopJS/blob/master/core/command/remote.js#L14 from:

const commandStr = `node ${ssws} ${projectPath} ${MIDDLEWARE_PATH} --config=${config.backstopConfigFileName}`;

to

const commandStr = `node "${ssws}" "${projectPath}" "${MIDDLEWARE_PATH}" --config="${config.backstopConfigFileName}"`;

Let me know if a PR is welcome?

BenceSzalai avatar Sep 13 '25 15:09 BenceSzalai

Hi, I am not able to put much effort into the project these days -- and while your suggestion looks simple enough you would not believe how side effects from simple things like this can wreak havoc on other users.

Does a simple backslash escape work?

I am open to the PR but you would need to commit to handling any regressions reported by the community.

garris avatar Sep 13 '25 19:09 garris

I know these are typically the kind of changes that can break things of others relying on different assumptions and quirks.

Escaping could also work, but that'd require a code change too, because these paths are the result of require.resolve and path.resolve calls, so the main issue is that there is no way to influence them from the user's perspective.

Thinking about it more, both escaping and enclosing in " can cause issues. Escaping spaces is different per OS, also Linux and Mac can have " in paths, so a naive quoting can also be a problem.

So probably the proper way to do it is using const { spawn } = require('child_process') instead of const { exec } = require('child_process');, because for spawn the arguments can be passed in an array, so that solves the issue with spaces or any unexpected characters for that matter.

I am happy to take care of this if such change would create more/other issues down the line for others.

BenceSzalai avatar Sep 14 '25 11:09 BenceSzalai