pull/638/head
yann300 4 years ago
parent 850d85fba8
commit baf86d9077
  1. 30
      libs/remixd/src/services/gitClient.ts

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

Loading…
Cancel
Save