diff --git a/src/MessageParser.php b/src/MessageParser.php index 426da5b..de97d00 100644 --- a/src/MessageParser.php +++ b/src/MessageParser.php @@ -92,6 +92,13 @@ class MessageParser { "vite", ]; + protected $versions = [ + "9.x", + "8.x", + "7.x", + "6.x", + ]; + public function __invoke($message) { $content = strtolower($message->content); @@ -103,12 +110,12 @@ public function __invoke($message) $query = substr($content, 5); // Check if version is available in command - $pattern = '/\b([6-9]\.x)\b/'; // only match 6.x to 9.x + $pattern = '/\b([0-9]+\.([0-9]|[x])+)\b/'; preg_match($pattern, $query, $matches); if ($matches) { $query = preg_replace($pattern, '', $query); - $version = $matches[0]; + $version = in_array($matches[0], $this->versions) ? $matches[0] : null; } $query = trim($query); diff --git a/tests/MessageParserTest.php b/tests/MessageParserTest.php index 2fa1396..7ade933 100644 --- a/tests/MessageParserTest.php +++ b/tests/MessageParserTest.php @@ -127,7 +127,9 @@ public function messageInputProvider() ["docs vite", ""], ["docs 9.x csrf", ""], ["docs 8.x csrf", ""], - ["docs 10.x csrf", false], + ["docs 10.x csrf", ""], + ["docs 5.4 csrf", ""], + ["docs csrf 5.4", ""], ["docs csrf 9.x", ""], ]; }