Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValidatingArrayLoader: only validate source/dist properties if they are set #10658

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Composer/Package/Loader/ValidatingArrayLoader.php
Expand Up @@ -352,10 +352,10 @@ public function load(array $config, string $class = 'Composer\Package\CompletePa
if ($srcType === 'source' && !isset($this->config[$srcType]['reference'])) {
$this->errors[] = $srcType . '.reference : must be present';
}
if (!is_string($this->config[$srcType]['type'])) {
if (isset($this->config[$srcType]['type']) && !is_string($this->config[$srcType]['type'])) {
$this->errors[] = $srcType . '.type : should be a string, '.gettype($this->config[$srcType]['type']).' given';
}
if (!is_string($this->config[$srcType]['url'])) {
if (isset($this->config[$srcType]['url']) && !is_string($this->config[$srcType]['url'])) {
$this->errors[] = $srcType . '.url : should be a string, '.gettype($this->config[$srcType]['url']).' given';
}
if (isset($this->config[$srcType]['reference']) && !is_string($this->config[$srcType]['reference']) && !is_int($this->config[$srcType]['reference'])) {
Expand All @@ -364,7 +364,7 @@ public function load(array $config, string $class = 'Composer\Package\CompletePa
if (isset($this->config[$srcType]['reference']) && Preg::isMatch('{^\s*-}', (string) $this->config[$srcType]['reference'])) {
$this->errors[] = $srcType . '.reference : must not start with a "-", "'.$this->config[$srcType]['reference'].'" given';
}
if (Preg::isMatch('{^\s*-}', $this->config[$srcType]['url'])) {
if (isset($this->config[$srcType]['url']) && Preg::isMatch('{^\s*-}', (string) $this->config[$srcType]['url'])) {
$this->errors[] = $srcType . '.url : must not start with a "-", "'.$this->config[$srcType]['url'].'" given';
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php
Expand Up @@ -417,6 +417,20 @@ public function errorProvider(): array
'require.foo/Bar : a package cannot set a require on itself',
),
),
array(
array(
'name' => 'foo/bar',
'source' => array('url' => 1),
'dist' => array('url' => null),
),
array(
'source.type : must be present',
'source.url : should be a string, integer given',
'source.reference : must be present',
'dist.type : must be present',
'dist.url : must be present',
),
),
));
}

Expand Down