Skip to content

Commit

Permalink
refactor(concerns): update getEscapeSudoPassword method
Browse files Browse the repository at this point in the history
- Rename getEscapeSudoPassword method to getEscapedSudoPassword
- Use EscapeArg::escape to escape sudo password
- Update shouldApplySudoPassword method logic
  • Loading branch information
guanguans committed Jul 14, 2023
1 parent d205948 commit 9ba70bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Concerns/HasSudoPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public function setSudoPassword(?string $sudoPassword): self
return $this;
}

protected function shouldApplySudoPassword(): bool
protected function getEscapedSudoPassword(): string
{
return $this->sudoPassword && OS::isUnix() && (\PHP_SAPI !== 'cli' && \PHP_SAPI !== 'phpdbg');
return EscapeArg::escape($this->sudoPassword);
}

protected function getEscapeSudoPassword(): string
protected function shouldApplySudoPassword(): bool
{
return EscapeArg::escape($this->sudoPassword);
return $this->sudoPassword && OS::isUnix() && ! \in_array(\PHP_SAPI, ['cli', 'cli-server', 'phpdbg'], true);
}
}
2 changes: 1 addition & 1 deletion src/Concerns/WithRunable.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private function createProcess($withOptions = [], ?callable $processTapper = nul
if ($this->shouldApplySudoPassword()) {
$process = Process::fromShellCommandline(sprintf(
'echo %s | sudo -S %s',
$this->getEscapeSudoPassword(),
$this->getEscapedSudoPassword(),
$process->getCommandLine()
));
}
Expand Down

0 comments on commit 9ba70bc

Please sign in to comment.