Browse Source

Moved file back to correct location. (+1 squashed commit)
Squashed commits:
[eec32aa] Updated detection to only allow composer.josn in root or first level dir.

Danack 11 years ago
parent
commit
24aba5b51f

+ 12 - 0
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.

+ 4 - 10
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(

+ 0 - 0
tests/Composer/Test/Repository/Fixtures/artifacts/correct/composer-1.0.0-alpha6.zip → tests/Composer/Test/Repository/Fixtures/artifacts/composer-1.0.0-alpha6.zip


BIN
tests/Composer/Test/Repository/Fixtures/artifacts/jsonInFirstLevel.zip


BIN
tests/Composer/Test/Repository/Fixtures/artifacts/jsonInRoot.zip


BIN
tests/Composer/Test/Repository/Fixtures/artifacts/jsonInSecondLevel.zip


+ 0 - 0
tests/Composer/Test/Repository/Fixtures/artifacts/correct/not-an-artifact.zip → tests/Composer/Test/Repository/Fixtures/artifacts/not-an-artifact.zip


+ 0 - 0
tests/Composer/Test/Repository/Fixtures/artifacts/correct/package0.zip → tests/Composer/Test/Repository/Fixtures/artifacts/package0.zip


+ 0 - 0
tests/Composer/Test/Repository/Fixtures/artifacts/correct/package2.zip → tests/Composer/Test/Repository/Fixtures/artifacts/package2.zip


+ 0 - 0
tests/Composer/Test/Repository/Fixtures/artifacts/correct/subfolder/not-an-artifact.zip → tests/Composer/Test/Repository/Fixtures/artifacts/subfolder/not-an-artifact.zip


+ 0 - 0
tests/Composer/Test/Repository/Fixtures/artifacts/correct/subfolder/package1.zip → tests/Composer/Test/Repository/Fixtures/artifacts/subfolder/package1.zip