Skip to content

Commit 1615043

Browse files
Make the shorthand detection more restrictive
In order to allow people to use scripts like `captainhook.sh` or `captainhook.php` the regex and the test examples got improved.
1 parent 78871dd commit 1615043

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/Runner/Shorthand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CaptainHook\App\Runner;
1313

1414
use CaptainHook\App\Hook;
15+
use PHPUnit\Framework\MockObject\MockObject;
1516
use RuntimeException;
1617

1718
/**
@@ -84,14 +85,14 @@ class Shorthand
8485
];
8586

8687
/**
87-
* Check if a configured action value is actually shorthand for an internal action
88+
* Check if a configured action or condition value is actually a shorthand for an internal action
8889
*
89-
* @param string $action
90+
* @param string $shorthand
9091
* @return bool
9192
*/
92-
public static function isShorthand(string $action): bool
93+
public static function isShorthand(string $shorthand): bool
9394
{
94-
return (bool) preg_match('#^captainhook\.[a-z]+#i', $action);
95+
return preg_match('#^captainhook\.[a-z]+\.[a-z]+$#i', $shorthand);
9596
}
9697

9798
/**

tests/unit/Runner/ShorthandTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ public function testCanIdentifyShorthand()
2525
$this->assertFalse(Shorthand::isShorthand('foo'));
2626
$this->assertFalse(Shorthand::isShorthand('\\CaptainHook\\App'));
2727
$this->assertFalse(Shorthand::isShorthand('CaptainHook.'));
28+
$this->assertFalse(Shorthand::isShorthand('captainhook.sh'));
2829

2930
// positive
30-
$this->assertTrue(Shorthand::isShorthand('CaptainHook.foo'));
31-
$this->assertTrue(Shorthand::isShorthand('captainhook.bar'));
32-
$this->assertTrue(Shorthand::isShorthand('CAPTAINHOOK.baz'));
31+
$this->assertTrue(Shorthand::isShorthand('CaptainHook.foo.fiz'));
32+
$this->assertTrue(Shorthand::isShorthand('captainhook.Bar.Baz'));
33+
$this->assertTrue(Shorthand::isShorthand('CAPTAINHOOK.FOO.BAR'));
3334
}
3435

3536
/**

0 commit comments

Comments
 (0)