Skip to content

Commit cd15c35

Browse files
committed
fix: don't handle spaces in unix
Signed-off-by: Ruben Romero Montes <[email protected]>
1 parent 2ba0c80 commit cd15c35

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

src/tools.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { EOL } from "os";
2-
import os from 'os';
32
import { execFileSync } from "child_process";
43
import { PackageURL } from "packageurl-js";
54

@@ -75,24 +74,16 @@ export function environmentVariableIsPopulated(envVariableName) {
7574
}
7675

7776
/**
78-
*
77+
* Utility function for handling spaces in paths on Windows
7978
* @param {string} path - path to be checked if contains spaces
8079
* @return {string} a path with all spaces escaped or manipulated so it will be able to be part
8180
* of commands that will be invoked without errors in os' shell.
8281
*/
8382
export function handleSpacesInPath(path) {
8483
let transformedPath = path
8584
// if operating system is windows
86-
if (os.platform() === "win32") {
87-
if(hasSpaces(path)) {
88-
transformedPath = `"${path}"`
89-
}
90-
}
91-
// linux, darwin..
92-
else {
93-
if(hasSpaces(path)) {
94-
transformedPath = path.replaceAll(" ", "\\ ")
95-
}
85+
if(hasSpaces(path)) {
86+
transformedPath = `"${path}"`
9687
}
9788
return transformedPath
9889
}
@@ -161,10 +152,9 @@ export function invokeCommand(bin, args, opts={}) {
161152
// https://github.com/nodejs/node/issues/52681#issuecomment-2076426887
162153
if (process.platform === 'win32') {
163154
opts = {...opts, shell: true}
155+
args = args.map(arg => handleSpacesInPath(arg))
156+
bin = handleSpacesInPath(bin)
164157
}
165-
// Handle spaces in paths for all platforms
166-
args = args.map(arg => handleSpacesInPath(arg))
167-
bin = handleSpacesInPath(bin)
168158

169159
opts = {
170160
...opts,

test/tools.test.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ suite('testing the various tools and utility functions', () => {
6868

6969
test('Windows Path with spaces', async () => {
7070
const tools = await mockToolsPartial("win32")
71-
7271
let path = "c:\\users\\john doe\\pom.xml"
7372
let expectedPath = "\"c:\\users\\john doe\\pom.xml\""
7473
let actualPath = tools.handleSpacesInPath(path)
@@ -83,22 +82,6 @@ suite('testing the various tools and utility functions', () => {
8382
expect(actualPath).to.equal(expectedPath)
8483
})
8584

86-
test('Linux Path with spaces', async () => {
87-
const tools = await mockToolsPartial("linux")
88-
let path = "/usr/john doe/pom.xml"
89-
let expectedPath = "/usr/john\\ doe/pom.xml"
90-
let actualPath = tools.handleSpacesInPath(path)
91-
expect(actualPath).to.equal(expectedPath)
92-
})
93-
94-
test('Linux Path with no spaces', async () => {
95-
const tools = await mockToolsPartial("linux")
96-
let path = "/usr/john/pom.xml"
97-
let expectedPath = "/usr/john/pom.xml"
98-
let actualPath = tools.handleSpacesInPath(path)
99-
expect(actualPath).to.equal(expectedPath)
100-
})
101-
10285
})
10386

10487

0 commit comments

Comments
 (0)