pull/5370/head
yann300 4 years ago
parent ff93ff17a0
commit 21fd423b24
  1. 18
      libs/remixd/src/services/gitClient.ts

@ -17,18 +17,13 @@ export class GitClient extends PluginClient {
this.readOnly = readOnly this.readOnly = readOnly
} }
command (cmd: string) { execute (cmd: string) {
return new Promise((resolve, reject) => { assertCommand(cmd)
try {
try {
validateCommand(cmd, gitRegex)
} catch (e) {
return reject(e)
}
const options = { cwd: this.currentSharedFolder, shell: true } const options = { cwd: this.currentSharedFolder, shell: true }
const child = spawn(cmd, options) const child = spawn(cmd, options)
let result = '' let result = ''
let error = '' let error = ''
return new Promise((resolve, reject) => {
child.stdout.on('data', (data) => { child.stdout.on('data', (data) => {
result += data.toString() result += data.toString()
}) })
@ -42,9 +37,6 @@ export class GitClient extends PluginClient {
resolve(result + error) resolve(result + error)
} }
}) })
} catch (e) {
reject(e)
}
}) })
} }
} }
@ -52,9 +44,9 @@ export class GitClient extends PluginClient {
/** /**
* Validate that command can be run by service * Validate that command can be run by service
* @param cmd * @param cmd
* @param regex
*/ */
function validateCommand (cmd, regex) { function assertCommand (cmd) {
const regex = '^git\\s[^&|;]*$'
if (!RegExp(regex).test(cmd)) { // git then space and then everything else if (!RegExp(regex).test(cmd)) { // git then space and then everything else
throw new Error('Invalid command for service!') throw new Error('Invalid command for service!')
} }

Loading…
Cancel
Save