diff --git a/app/src/lib/helpers/linux.ts b/app/src/lib/helpers/linux.ts index 73fe58887fe..e6e021808b0 100644 --- a/app/src/lib/helpers/linux.ts +++ b/app/src/lib/helpers/linux.ts @@ -28,7 +28,9 @@ export function convertToFlatpakPath(path: string) { return join('/var/run/host', path) } - +export function formatWorkingDirectoryForFlatpak(path: string): string { + return path.replace(/(\s)/, "\ ") +} /** * Checks the file path on disk exists before attempting to launch a specific shell * @@ -82,9 +84,10 @@ export function spawnEditor( options: SpawnOptions ): ChildProcess { if (isFlatpakBuild()) { + let EscapedworkingDirectory = formatWorkingDirectoryForFlatpak(workingDirectory) return spawn( 'flatpak-spawn', - ['--host', path, `"${workingDirectory}"`], + ['--host', path, EscapedworkingDirectory], options ) } else { diff --git a/app/test/unit/helpers/linux-test.ts b/app/test/unit/helpers/linux-test.ts index df18564e441..0f6895c8835 100644 --- a/app/test/unit/helpers/linux-test.ts +++ b/app/test/unit/helpers/linux-test.ts @@ -1,4 +1,4 @@ -import { convertToFlatpakPath } from '../../../src/lib/helpers/linux' +import { convertToFlatpakPath, formatWorkingDirectoryForFlatpak } from '../../../src/lib/helpers/linux' describe('convertToFlatpakPath()', () => { if (__LINUX__) { @@ -28,3 +28,17 @@ describe('convertToFlatpakPath()', () => { }) } }) + +describe('formatWorkingDirectoryForFlatpak()', () => { + if (__LINUX__) { + it('escapes string', () => { + const path = "/home/test/path with space" + const expectedPath = "/home/test/path\ with\ space" + expect(formatWorkingDirectoryForFlatpak(path)).toEqual(expectedPath) + }) + it('returns same path', () => { + const path = "/home/test/path_wthout_spaces" + expect(formatWorkingDirectoryForFlatpak(path)).toEqual(path) + }) + } +})