Skip to content

Commit

Permalink
escape paths with regex over quotes in flatpaks (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunarequest authored and shiftkey committed Oct 22, 2021
1 parent 5dcc746 commit efad394
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 7 additions & 2 deletions app/src/lib/helpers/linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 18 additions & 1 deletion app/test/unit/helpers/linux-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { convertToFlatpakPath } from '../../../src/lib/helpers/linux'
import {
convertToFlatpakPath,
formatWorkingDirectoryForFlatpak,
} from '../../../src/lib/helpers/linux'

describe('convertToFlatpakPath()', () => {
if (__LINUX__) {
Expand Down Expand Up @@ -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)
})
}
})

0 comments on commit efad394

Please sign in to comment.