diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 5581dbb..b9997c7 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,13 +5,11 @@
-
-
-
-
+
+
+
-
@@ -20,70 +18,64 @@
$PROJECT_DIR$/composer.json
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
+
+
-
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
@@ -91,36 +83,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ->setUrl
- EVENT_LOAD
addRoute
$this->isPro
7.2
@@ -137,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
@@ -196,7 +164,6 @@
-
@@ -208,19 +175,20 @@
-
-
-
+
-
+
+
+
+
@@ -237,7 +205,7 @@
true
DEFINITION_ORDER
-
+
@@ -278,7 +246,6 @@
-
@@ -290,108 +257,73 @@
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
+
@@ -434,40 +366,43 @@
-
+
+
-
-
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
@@ -542,45 +477,46 @@
-
-
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
@@ -592,32 +528,32 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -626,31 +562,11 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -664,23 +580,59 @@
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -688,105 +640,89 @@
-
+
-
+
-
-
-
-
-
-
-
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
+
-
-
-
-
-
-
-
-
+
@@ -807,59 +743,56 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
+
-
+
@@ -867,7 +800,7 @@
-
+
@@ -876,83 +809,91 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
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');
});