diff --git a/app/src/lib/helpers/linux.ts b/app/src/lib/helpers/linux.ts index 73fe58887fe..fbe3c7742e2 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,12 @@ export function spawnEditor( options: SpawnOptions ): ChildProcess { if (isFlatpakBuild()) { + const 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..52873f4e9d0 100644 --- a/app/test/unit/helpers/linux-test.ts +++ b/app/test/unit/helpers/linux-test.ts @@ -1,4 +1,7 @@ -import { convertToFlatpakPath } from '../../../src/lib/helpers/linux' +import { + convertToFlatpakPath, + formatWorkingDirectoryForFlatpak, +} from '../../../src/lib/helpers/linux' describe('convertToFlatpakPath()', () => { if (__LINUX__) { @@ -28,3 +31,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) + }) + } +})