Skip to content

Commit

Permalink
handle slashes in version criteria. Fix Bee-Lab#120
Browse files Browse the repository at this point in the history
  • Loading branch information
garak committed Aug 12, 2015
1 parent 6c5611c commit 8beae81
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 149 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- 5.4
- 5.5
- 5.6
- nightly

env:
- BOWERPHP_TOKEN=00fe3b72344a637f8d28696f8a73ef67c9fa64e2 SYMFONY_DEPRECATIONS_HELPER=weak
Expand All @@ -17,3 +18,7 @@ before_script:

script:
- phpunit

matrix:
allow_failures:
- php: nightly
259 changes: 127 additions & 132 deletions composer.lock

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions src/Bowerphp/Bowerphp.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Version @package_version@
* Released on the @release_date@
*/

namespace Bowerphp;
Expand Down
12 changes: 5 additions & 7 deletions src/Bowerphp/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
use Symfony\Component\Finder\Finder;

/**
* The Compiler class compiles Bower into a phar
* The Compiler class compiles Bower into a phar.
*/
class Compiler
{
/**
* @var bool
*/
private $gz;

/**
Expand Down Expand Up @@ -103,7 +106,7 @@ public function compile($pharFile = 'bowerphp.phar')
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../LICENSE'), false);

unset($phar);
chmod("bowerphp.phar", 0700);
chmod('bowerphp.phar', 0700);
}

/**
Expand All @@ -122,11 +125,6 @@ private function addFile(\Phar $phar, \SplFileInfo $file, $strip = true)
$content = "\n" . $content . "\n";
}

if ($path === 'src/Bowerphp/Bowerphp.php') {
$content = str_replace('@package_version@', $this->version, $content);
$content = str_replace('@release_date@', $this->versionDate, $content);
}

$phar->addFromString($path, $content);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Bowerphp/Installer/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function filterZipFiles(ZipArchive $archive, array $ignore = array(),
$dirName = $archive->getNameIndex(0);
$return = array();
$numFiles = $archive->getNumFiles();
for ($i = 0; $i < $numFiles; $i++) {
for ($i = 0; $i < $numFiles; ++$i) {
$stat = $archive->statIndex($i);
$return[] = $stat['name'];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bowerphp/Output/BowerphpConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function writelnInstalledPackage(PackageInterface $package)
public function writelnNoBowerJsonFile()
{
$this->output->writeln(sprintf('bower <info>%s</info> <fg=yellow>%s</fg=yellow> %s',
str_pad("", 21, ' ', STR_PAD_RIGHT),
str_pad('', 21, ' ', STR_PAD_RIGHT),
str_pad('no-json', 10, ' ', STR_PAD_LEFT),
'No bower.json file to save to, use bower init to create one', 10, ' ', STR_PAD_LEFT
));
Expand Down
14 changes: 12 additions & 2 deletions src/Bowerphp/Repository/GithubRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Bowerphp\Repository;

use Bowerphp\Util\ArrayColumn;
use Bowerphp\Util\Json;
use Github\Client;
use Github\ResultPager;
Expand Down Expand Up @@ -113,10 +114,19 @@ public function findPackage($rawCriteria = '*')
return $this->tag['name'];
}

// edge case for versions vith slash (like ckeditor). See also issue #120
if (strpos($rawCriteria, '/') > 0) {
$tagNames = ArrayColumn::array_column($tags, 'name');
if (false !== $tag = array_search($rawCriteria, $tagNames)) {
$this->tag = $tag;
return $rawCriteria;
}
}

try {
$criteria = new expression($rawCriteria);
} catch (SemVerException $sve) {
throw new RuntimeException(sprintf('Criteria %s is not valid.', $rawCriteria), self::INVALID_CRITERIA);
throw new RuntimeException(sprintf('Criteria %s is not valid.', $rawCriteria), self::INVALID_CRITERIA, $sve);
}
$sortedTags = $this->sortTags($tags);

Expand Down Expand Up @@ -253,7 +263,7 @@ private function fixupRawTag($rawValue)
$pieces[] = '0';
$count = 1;
}
for ($add = $count; $add < 3; $add++) {
for ($add = $count; $add < 3; ++$add) {
$pieces[] = '0';
}
$return = implode('.', array_slice($pieces, 0, 3));
Expand Down
39 changes: 39 additions & 0 deletions src/Bowerphp/Util/ArrayColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of Bowerphp.
*
* (c) Massimiliano Arione <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Bowerphp\Util;

/**
* ArrayColumn.
*/
class ArrayColumn
{
/**
* Wrapper for PHP < 5.5.
* See {@link http://php.net/manual/en/function.array-column.php}.
*
* @param array $array
* @param mixed $column_name
* @param mixed $index
*
* @return array
*/
public static function array_column(array $array, $column_name, $index = null)
{
if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
return array_column($array, $column_name, $index);
}

return array_map(function ($element) use ($column_name) {
return $element[$column_name];
}, $array);
}
}
7 changes: 4 additions & 3 deletions src/Bowerphp/Util/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
class Json
{
/**
* FOR php 5.3 from php >= 5.4* use parameter JSON_PRETTY_PRINT
* See http://www.php.net/manual/en/function.json-encode.php
* For PHP 5.3 from php >= 5.4* use parameter JSON_PRETTY_PRINT.
* See {@link http://www.php.net/manual/en/function.json-encode.php}.
*
* @param mixed $value
*
* @param mixed $value
* @return string
*/
public static function encode($value)
Expand Down
9 changes: 9 additions & 0 deletions tests/Bowerphp/Test/Command/InfoCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public function testExecuteWithRenamedRepo()
$this->assertRegExp('/jquery-hammerjs/', $commandTester->getDisplay());
}

public function testExecuteWithSlashedVersion()
{
$application = new Application();
$commandTester = new CommandTester($command = $application->get('info'));
$commandTester->execute(array('command' => $command->getName(), 'package' => 'ckeditor#full/4.5.2'), array('decorated' => false));

$this->assertRegExp('/name: \'ckeditor\'/', $commandTester->getDisplay());
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Not enough arguments.
Expand Down

0 comments on commit 8beae81

Please sign in to comment.