-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix invalid files being listed in "log" command (#1361)
Ignores output from other processes during the SSH connection
- Loading branch information
1 parent
7111185
commit 5a0eb35
Showing
4 changed files
with
60 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Platformsh\Cli\Util; | ||
|
||
class StringUtil | ||
{ | ||
/** | ||
* Finds a substring between two delimiters. | ||
* | ||
* @param string $str | ||
* @param string $begin | ||
* @param string $end | ||
* | ||
* @return string|null | ||
* The substring, or null if the delimiters are not found. | ||
*/ | ||
public static function between($str, $begin, $end) | ||
{ | ||
$first = \strpos($str, $begin); | ||
$last = \strrpos($str, $end, $first); | ||
if ($first === false || $last === false) { | ||
return null; | ||
} | ||
$offset = $first + \strlen($begin); | ||
$length = $last - $first - \strlen($begin); | ||
return \substr($str, $offset, $length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Platformsh\Cli\Tests\Util; | ||
|
||
use Platformsh\Cli\Util\StringUtil; | ||
|
||
class StringUtilTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testBetween() | ||
{ | ||
$cases = [ | ||
['_BEGIN_foo_END_', '_BEGIN_', '_END_', 'foo'], | ||
['_BEGIN_foo bar', '_BEGIN_', '_END_', null], | ||
['_BEGIN_foo bar_END_', '_BEGIN_', '_END_', 'foo bar'], | ||
["_BEGIN_\nfoo\n_END_", '_BEGIN_', '_END_', "\nfoo\n"], | ||
["_BEGIN_\nfoo\n_END_", "_BEGIN_\n", '_END_', "foo\n"], | ||
["_BEGIN_\nfoo\n_END_", "_BEGIN_\n", "\n_END_", 'foo'], | ||
]; | ||
foreach ($cases as $key => $case) { | ||
list($str, $begin, $end, $result) = $case; | ||
$this->assertEquals($result, StringUtil::between($str, $begin, $end), "case $key"); | ||
} | ||
} | ||
} |