diff --git a/src/Composer/Repository/ArtifactRepository.php b/src/Composer/Repository/ArtifactRepository.php index 769e35b40..34ed64ea3 100644 --- a/src/Composer/Repository/ArtifactRepository.php +++ b/src/Composer/Repository/ArtifactRepository.php @@ -88,6 +88,18 @@ class ArtifactRepository extends ArrayRepository for ($i = 0; $i < $zip->numFiles; $i++ ){ $stat = $zip->statIndex($i); if (strcmp(basename($stat['name']), $filename) === 0){ + $directoryName = dirname($stat['name']); + if ($directoryName == '.') { + //if composer.json is in root directory + //it has to be the one to use. + return $i; + } + + if(strpos($directoryName, '\\') !== false || + strpos($directoryName, '/') !== false) { + continue; + } + $length = strlen($stat['name']); if ($indexOfShortestMatch == false || $length < $lengthOfShortestMatch) { //Check it's not a directory. diff --git a/tests/Composer/Test/Repository/ArtifactRepositoryTest.php b/tests/Composer/Test/Repository/ArtifactRepositoryTest.php index f83ceee8c..1958f5b9f 100644 --- a/tests/Composer/Test/Repository/ArtifactRepositoryTest.php +++ b/tests/Composer/Test/Repository/ArtifactRepositoryTest.php @@ -27,10 +27,12 @@ class ArtifactRepositoryTest extends TestCase 'vendor1/package2-4.3.2', 'vendor3/package1-5.4.3', 'test/jsonInRoot-1.0.0', - 'test/jsonInFirstLevel-1.0.0' + 'test/jsonInFirstLevel-1.0.0', + //The files not-an-artifact.zip and jsonSecondLevel are not valid + //artifacts and do not get detected. ); - $coordinates = array('type' => 'artifact', 'url' => __DIR__ . '/Fixtures/artifacts/correct'); + $coordinates = array('type' => 'artifact', 'url' => __DIR__ . '/Fixtures/artifacts'); $repo = new ArtifactRepository($coordinates, new NullIO(), new Config()); $foundPackages = array_map(function(BasePackage $package) { @@ -42,14 +44,6 @@ class ArtifactRepositoryTest extends TestCase $this->assertSame($expectedPackages, $foundPackages); } - - public function testExtractConfigFails() - { - $this->setExpectedException('RuntimeException', "Shouldn't have picked up composer.json from a location other than root or first level directory."); - - $coordinates = array('type' => 'artifact', 'url' => __DIR__ . '/Fixtures/artifacts/error/jsonWrongDirectory'); - new ArtifactRepository($coordinates, new NullIO(), new Config()); - } } //$archivesToCreate = array( diff --git a/tests/Composer/Test/Repository/Fixtures/artifacts/correct/composer-1.0.0-alpha6.zip b/tests/Composer/Test/Repository/Fixtures/artifacts/composer-1.0.0-alpha6.zip similarity index 100% rename from tests/Composer/Test/Repository/Fixtures/artifacts/correct/composer-1.0.0-alpha6.zip rename to tests/Composer/Test/Repository/Fixtures/artifacts/composer-1.0.0-alpha6.zip diff --git a/tests/Composer/Test/Repository/Fixtures/artifacts/jsonInFirstLevel.zip b/tests/Composer/Test/Repository/Fixtures/artifacts/jsonInFirstLevel.zip new file mode 100644 index 000000000..498037464 Binary files /dev/null and b/tests/Composer/Test/Repository/Fixtures/artifacts/jsonInFirstLevel.zip differ diff --git a/tests/Composer/Test/Repository/Fixtures/artifacts/jsonInRoot.zip b/tests/Composer/Test/Repository/Fixtures/artifacts/jsonInRoot.zip new file mode 100644 index 000000000..7b2a87eb9 Binary files /dev/null and b/tests/Composer/Test/Repository/Fixtures/artifacts/jsonInRoot.zip differ diff --git a/tests/Composer/Test/Repository/Fixtures/artifacts/jsonInSecondLevel.zip b/tests/Composer/Test/Repository/Fixtures/artifacts/jsonInSecondLevel.zip new file mode 100644 index 000000000..0e5abc61b Binary files /dev/null and b/tests/Composer/Test/Repository/Fixtures/artifacts/jsonInSecondLevel.zip differ diff --git a/tests/Composer/Test/Repository/Fixtures/artifacts/correct/not-an-artifact.zip b/tests/Composer/Test/Repository/Fixtures/artifacts/not-an-artifact.zip similarity index 100% rename from tests/Composer/Test/Repository/Fixtures/artifacts/correct/not-an-artifact.zip rename to tests/Composer/Test/Repository/Fixtures/artifacts/not-an-artifact.zip diff --git a/tests/Composer/Test/Repository/Fixtures/artifacts/correct/package0.zip b/tests/Composer/Test/Repository/Fixtures/artifacts/package0.zip similarity index 100% rename from tests/Composer/Test/Repository/Fixtures/artifacts/correct/package0.zip rename to tests/Composer/Test/Repository/Fixtures/artifacts/package0.zip diff --git a/tests/Composer/Test/Repository/Fixtures/artifacts/correct/package2.zip b/tests/Composer/Test/Repository/Fixtures/artifacts/package2.zip similarity index 100% rename from tests/Composer/Test/Repository/Fixtures/artifacts/correct/package2.zip rename to tests/Composer/Test/Repository/Fixtures/artifacts/package2.zip diff --git a/tests/Composer/Test/Repository/Fixtures/artifacts/correct/subfolder/not-an-artifact.zip b/tests/Composer/Test/Repository/Fixtures/artifacts/subfolder/not-an-artifact.zip similarity index 100% rename from tests/Composer/Test/Repository/Fixtures/artifacts/correct/subfolder/not-an-artifact.zip rename to tests/Composer/Test/Repository/Fixtures/artifacts/subfolder/not-an-artifact.zip diff --git a/tests/Composer/Test/Repository/Fixtures/artifacts/correct/subfolder/package1.zip b/tests/Composer/Test/Repository/Fixtures/artifacts/subfolder/package1.zip similarity index 100% rename from tests/Composer/Test/Repository/Fixtures/artifacts/correct/subfolder/package1.zip rename to tests/Composer/Test/Repository/Fixtures/artifacts/subfolder/package1.zip