Skip to content

Commit

Permalink
fix signal handling for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
medilies committed Aug 7, 2024
1 parent 072f94c commit b989eef
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Dompurify/DompurifyCli.php
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public function exec(string $html): string
{
$htmlFile = $this->saveHtml($html);

$binPath = __DIR__.'/cli.js';
$binPath = __DIR__.DIRECTORY_SEPARATOR.'cli.js';

$binAbsPath = realpath($binPath);

20 changes: 18 additions & 2 deletions src/Dompurify/DompurifyService.php
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ public function start(): static
{
$this->serviceProcess = new Process([
$this->config->nodePath,
__DIR__.'/http.js',
__DIR__.DIRECTORY_SEPARATOR.'http.js',
$this->config->host,
$this->config->port,
]);
@@ -106,7 +106,8 @@ public function throwIfFailedOnTerm(): void
throw new XsslessException('The service is still running');
}

if ($this->serviceProcess->getTermSignal() === SIGTERM) {
// TODO: fix windows check
if ($this->isSigTerm() || $this->isWindows()) {
return;
}

@@ -130,4 +131,19 @@ public function waitForTermination(int $timeout): void
}

// ========================================================================

private function isWindows(): bool
{
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}

private function isSigTerm(): bool
{
return $this->serviceProcess->getTermSignal() === 15;
}

private function isSigHup(): bool

Check failure on line 145 in src/Dompurify/DompurifyService.php

GitHub Actions / phpstan

Method Medilies\Xssless\Dompurify\DompurifyService::isSigHup() is unused.

Check failure on line 145 in src/Dompurify/DompurifyService.php

GitHub Actions / phpstan

Method Medilies\Xssless\Dompurify\DompurifyService::isSigHup() is unused.
{
return $this->serviceProcess->getTermSignal() === 1;
}
}

0 comments on commit b989eef

Please sign in to comment.