Skip to content
Snippets Groups Projects
Commit 71f849dc authored by Yash Rode's avatar Yash Rode Committed by Adam G-H
Browse files

Issue #3357578 by yash.rode, Wim Leers, phenaproxima: str_starts_with($path,...

Issue #3357578 by yash.rode, Wim Leers, phenaproxima: str_starts_with($path, '/') does not correctly detect absolute paths on Windows
parent 24620958
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ namespace Drupal\package_manager\PathExcluder;
use Drupal\package_manager\ComposerInspector;
use Drupal\package_manager\Event\CollectPathsToExcludeEvent;
use Drupal\package_manager\PathLocator;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
......@@ -28,9 +29,12 @@ final class GitExcluder implements EventSubscriberInterface {
* The path locator service.
* @param \Drupal\package_manager\ComposerInspector $composerInspector
* The Composer inspector service.
* @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory
* The path factory service.
*/
public function __construct(PathLocator $path_locator, private readonly ComposerInspector $composerInspector) {
public function __construct(PathLocator $path_locator, private readonly ComposerInspector $composerInspector, PathFactoryInterface $path_factory) {
$this->pathLocator = $path_locator;
$this->pathFactory = $path_factory;
}
/**
......
......@@ -6,6 +6,7 @@ namespace Drupal\package_manager\PathExcluder;
use Drupal\package_manager\Event\CollectPathsToExcludeEvent;
use Drupal\package_manager\PathLocator;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
......@@ -25,9 +26,12 @@ class NodeModulesExcluder implements EventSubscriberInterface {
*
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
* @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory
* The path factory service.
*/
public function __construct(PathLocator $path_locator) {
public function __construct(PathLocator $path_locator, PathFactoryInterface $path_factory) {
$this->pathLocator = $path_locator;
$this->pathFactory = $path_factory;
}
/**
......
......@@ -18,6 +18,13 @@ trait PathExclusionsTrait {
*/
protected $pathLocator;
/**
* The path factory service.
*
* @var \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface
*/
protected $pathFactory;
/**
* Flags paths to be excluded, relative to the web root.
*
......@@ -56,7 +63,7 @@ trait PathExclusionsTrait {
$project_root = $this->pathLocator->getProjectRoot();
foreach ($paths as $path) {
if (str_starts_with($path, '/')) {
if ($this->pathFactory->create($path)->isAbsolute()) {
if (!str_starts_with($path, $project_root)) {
throw new \LogicException("$path is not inside the project root: $project_root.");
}
......
......@@ -6,6 +6,7 @@ namespace Drupal\package_manager\PathExcluder;
use Drupal\package_manager\Event\CollectPathsToExcludeEvent;
use Drupal\package_manager\PathLocator;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
......@@ -27,9 +28,12 @@ class SiteConfigurationExcluder implements EventSubscriberInterface {
* The current site path, relative to the Drupal root.
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
* @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory
* The path factory service.
*/
public function __construct(protected string $sitePath, PathLocator $path_locator) {
public function __construct(protected string $sitePath, PathLocator $path_locator, PathFactoryInterface $path_factory) {
$this->pathLocator = $path_locator;
$this->pathFactory = $path_factory;
}
/**
......
......@@ -8,6 +8,7 @@ use Drupal\Core\StreamWrapper\LocalStream;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\package_manager\Event\CollectPathsToExcludeEvent;
use Drupal\package_manager\PathLocator;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Filesystem\Filesystem;
......@@ -28,6 +29,8 @@ final class SiteFilesExcluder implements EventSubscriberInterface {
*
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
* @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory
* The path factory service.
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $streamWrapperManager
* The stream wrapper manager service.
* @param \Symfony\Component\Filesystem\Filesystem $fileSystem
......@@ -35,10 +38,12 @@ final class SiteFilesExcluder implements EventSubscriberInterface {
*/
public function __construct(
PathLocator $path_locator,
PathFactoryInterface $path_factory,
private readonly StreamWrapperManagerInterface $streamWrapperManager,
private readonly Filesystem $fileSystem
) {
$this->pathLocator = $path_locator;
$this->pathFactory = $path_factory;
}
/**
......
......@@ -7,6 +7,7 @@ namespace Drupal\package_manager\PathExcluder;
use Drupal\Core\Database\Connection;
use Drupal\package_manager\Event\CollectPathsToExcludeEvent;
use Drupal\package_manager\PathLocator;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
......@@ -28,9 +29,12 @@ class SqliteDatabaseExcluder implements EventSubscriberInterface {
* The path locator service.
* @param \Drupal\Core\Database\Connection $database
* The database connection.
* @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory
* The path factory service.
*/
public function __construct(PathLocator $path_locator, protected Connection $database) {
public function __construct(PathLocator $path_locator, protected Connection $database, PathFactoryInterface $path_factory) {
$this->pathLocator = $path_locator;
$this->pathFactory = $path_factory;
}
/**
......
......@@ -6,6 +6,7 @@ namespace Drupal\package_manager\PathExcluder;
use Drupal\package_manager\Event\CollectPathsToExcludeEvent;
use Drupal\package_manager\PathLocator;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
......@@ -25,9 +26,12 @@ final class TestSiteExcluder implements EventSubscriberInterface {
*
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
* @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory
* The path factory service.
*/
public function __construct(PathLocator $path_locator) {
public function __construct(PathLocator $path_locator, PathFactoryInterface $path_factory) {
$this->pathLocator = $path_locator;
$this->pathFactory = $path_factory;
}
/**
......
......@@ -8,6 +8,7 @@ use Drupal\Component\Serialization\Json;
use Drupal\package_manager\ComposerInspector;
use Drupal\package_manager\Event\CollectPathsToExcludeEvent;
use Drupal\package_manager\PathLocator;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
......@@ -39,9 +40,12 @@ final class UnknownPathExcluder implements EventSubscriberInterface {
* The Composer inspector service.
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
* @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory
* The path factory service.
*/
public function __construct(private readonly ComposerInspector $composerInspector, PathLocator $path_locator) {
public function __construct(private readonly ComposerInspector $composerInspector, PathLocator $path_locator, PathFactoryInterface $path_factory) {
$this->pathLocator = $path_locator;
$this->pathFactory = $path_factory;
}
/**
......
......@@ -6,6 +6,7 @@ namespace Drupal\package_manager\PathExcluder;
use Drupal\package_manager\Event\CollectPathsToExcludeEvent;
use Drupal\package_manager\PathLocator;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
......@@ -25,9 +26,12 @@ final class VendorHardeningExcluder implements EventSubscriberInterface {
*
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
* @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory
* The path factory service.
*/
public function __construct(PathLocator $path_locator) {
public function __construct(PathLocator $path_locator, PathFactoryInterface $path_factory) {
$this->pathLocator = $path_locator;
$this->pathFactory = $path_factory;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment