diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 3cf5d38..b9997c7 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,13 +6,10 @@
-
-
-
+
-
@@ -21,67 +18,64 @@
$PROJECT_DIR$/composer.json
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
+
+
-
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
@@ -89,36 +83,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ->setUrl
- EVENT_LOAD
addRoute
$this->isPro
7.2
@@ -135,18 +103,20 @@
matchRoute
->getValue
->find
-
+ function find
Req
value(
file(
setUrl
TODO
input()->get
-
+ function get
REQUEST_TYPE_
-
+ or method
setDebugEnabled
debugEnabled
+ optiona
+ \/
D:\Workspace\simple-php-router\src\Pecee\SimpleRouter\Route
@@ -194,7 +164,6 @@
-
@@ -206,19 +175,20 @@
-
-
-
+
+
+
+
@@ -296,82 +266,58 @@
-
+
-
-
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
@@ -420,34 +366,40 @@
-
+
+
-
-
+
+
+
+
+
+
+
+
-
-
+
+
+
-
-
@@ -525,44 +477,46 @@
-
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
@@ -577,29 +531,29 @@
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
@@ -608,26 +562,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -723,13 +658,6 @@
-
-
-
-
-
-
-
@@ -769,9 +697,6 @@
-
-
-
@@ -801,13 +726,6 @@
-
-
-
-
-
-
-
@@ -868,9 +786,6 @@
-
-
-
@@ -900,7 +815,7 @@
-
+
@@ -910,7 +825,7 @@
-
+
@@ -918,19 +833,9 @@
-
-
-
-
-
-
-
-
-
-
-
+
@@ -938,19 +843,9 @@
-
-
-
-
-
-
-
-
-
-
-
+
@@ -962,10 +857,41 @@
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Pecee/SimpleRouter/Route/Route.php b/src/Pecee/SimpleRouter/Route/Route.php
index 80a3dce..f04800a 100644
--- a/src/Pecee/SimpleRouter/Route/Route.php
+++ b/src/Pecee/SimpleRouter/Route/Route.php
@@ -152,8 +152,6 @@ abstract class Route implements IRoute
if (isset($this->where[$name]) === true) {
$regex = $this->where[$name];
} else {
-
- /* If method specific regex is defined use that, otherwise use the default parameter regex */
if ($parameterRegex !== null) {
$regex = $parameterRegex;
} else {
@@ -161,7 +159,7 @@ abstract class Route implements IRoute
}
}
- $regex = sprintf('(?:\/|\-)%1$s(?P<%2$s>%3$s)%1$s', $parameters[2][$key], $name, $regex);
+ $regex = sprintf('((\/|\-)(?P<%2$s>%3$s))%1$s', $parameters[2][$key], $name, $regex);
}
$urlRegex .= preg_quote($t, '/') . $regex;
diff --git a/tests/Pecee/SimpleRouter/RouterRouteTest.php b/tests/Pecee/SimpleRouter/RouterRouteTest.php
index 8e3caea..0571799 100644
--- a/tests/Pecee/SimpleRouter/RouterRouteTest.php
+++ b/tests/Pecee/SimpleRouter/RouterRouteTest.php
@@ -6,10 +6,28 @@ require_once 'Dummy/Exception/ExceptionHandlerException.php';
class RouterRouteTest extends \PHPUnit\Framework\TestCase
{
+
+ /**
+ * Issue #421: Incorrectly optional character in route
+ *
+ * @throws Exception
+ */
+ public function testOptionalCharacterRoute()
+ {
+ $result = false;
+ TestRouter::get('/api/v1/users/{userid}/projects/{id}/pages/{pageid?}', function () use (&$result) {
+ $result = true;
+ });
+
+ TestRouter::debug('/api/v1/users/1/projects/8399421535/pages/43/', 'get');
+
+ $this->assertTrue($result);
+ }
+
public function testMultiParam()
{
$result = false;
- TestRouter::get('/test-{param1}-{param2}', function ($param1, $param2) use(&$result) {
+ TestRouter::get('/test-{param1}-{param2}', function ($param1, $param2) use (&$result) {
if ($param1 === 'param1' && $param2 === 'param2') {
$result = true;
@@ -94,13 +112,12 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
$result = false;
TestRouter::request()->setHost('hello.world.com');
- TestRouter::group(['domain' => '{subdomain}.world.com'], function () use(&$result) {
- TestRouter::get('/test', function ($subdomain = null) use(&$result) {
+ TestRouter::group(['domain' => '{subdomain}.world.com'], function () use (&$result) {
+ TestRouter::get('/test', function ($subdomain = null) use (&$result) {
$result = ($subdomain === 'hello');
});
});
-
TestRouter::debug('/test', 'get');
$this->assertTrue($result);
@@ -113,8 +130,8 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
$result = false;
- TestRouter::group(['domain' => '{subdomain}.world.com'], function () use(&$result) {
- TestRouter::get('/test', function ($subdomain = null) use(&$result) {
+ TestRouter::group(['domain' => '{subdomain}.world.com'], function () use (&$result) {
+ TestRouter::get('/test', function ($subdomain = null) use (&$result) {
$result = ($subdomain === 'hello');
});
});
@@ -133,11 +150,12 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
$this->assertTrue(true);
}
- public function testParameterDefaultValue() {
+ public function testParameterDefaultValue()
+ {
$defaultVariable = null;
- TestRouter::get('/my/{path?}', function($path = 'working') use(&$defaultVariable) {
+ TestRouter::get('/my/{path?}', function ($path = 'working') use (&$defaultVariable) {
$defaultVariable = $path;
});
@@ -157,7 +175,7 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
public function testDefaultParameterRegexGroup()
{
- TestRouter::group(['defaultParameterRegex' => '[\w\-]+'], function() {
+ TestRouter::group(['defaultParameterRegex' => '[\w\-]+'], function () {
TestRouter::get('/my/{path}', 'DummyController@param');
});