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 Jul 19, 2021
1 parent 1a0dbf1 commit d8d8648
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 5 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,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 {
Expand Down
16 changes: 15 additions & 1 deletion app/test/unit/helpers/linux-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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 +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)
})
}
})

0 comments on commit d8d8648

Please sign in to comment.