Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
95231195
Commit
95231195
authored
Jul 29, 2014
by
alexpott
Browse files
Issue
#2051877
by dawehner, sun, tstoeckler: Log error when people use invalid route parameters.
parent
b0152299
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php
View file @
95231195
...
...
@@ -33,16 +33,12 @@ protected function alterRoutes(RouteCollection $collection) {
'_content'
,
'_form'
,
);
foreach
(
$collection
->
all
()
as
$route
)
{
foreach
(
$collection
->
all
()
as
$name
=>
$route
)
{
if
(
$not_allowed_variables
=
array_intersect
(
$route
->
compile
()
->
getVariables
(),
$special_variables
))
{
$placeholders
=
array
(
'@variables'
=>
implode
(
', '
,
$not_allowed_variables
));
drupal_set_message
(
String
::
format
(
'The following variables are reserved names by drupal: @variables'
,
$placeholders
));
watchdog
(
'error'
,
'The following variables are reserved names by drupal: @variables'
,
$placeholders
);
return
FALSE
;
$reserved
=
implode
(
', '
,
$not_allowed_variables
);
trigger_error
(
sprintf
(
'Route %s uses reserved variable names: %s'
,
$name
,
$reserved
),
E_USER_WARNING
);
}
}
return
TRUE
;
}
/**
...
...
core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php
View file @
95231195
...
...
@@ -5,7 +5,7 @@
* Contains \Drupal\Tests\Core\EventSubscriber\SpecialAttributesRouteSubscriberTest.
*/
namespace
Drupal\Tests\Core\EventSubscriber
{
namespace
Drupal\Tests\Core\EventSubscriber
;
use
Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber
;
use
Drupal\Core\Routing\RouteBuildEvent
;
...
...
@@ -85,7 +85,7 @@ public function testOnRouteBuildingValidVariables(Route $route) {
$route_collection
=
new
RouteCollection
();
$route_collection
->
add
(
'test'
,
$route
);
$event
=
new
RouteBuildEvent
(
$route_collection
,
'test'
);
$this
->
assertTrue
(
$this
->
specialAttributesRouteSubscriber
->
onAlterRoutes
(
$event
)
)
;
$this
->
specialAttributesRouteSubscriber
->
onAlterRoutes
(
$event
);
}
/**
...
...
@@ -95,25 +95,14 @@ public function testOnRouteBuildingValidVariables(Route $route) {
* The route to check.
*
* @dataProvider providerTestOnRouteBuildingInvalidVariables
* @expectedException \PHPUnit_Framework_Error_Warning
* @expectedExceptionMessage uses reserved variable names
*/
public
function
testOnRouteBuildingInvalidVariables
(
Route
$route
)
{
$route_collection
=
new
RouteCollection
();
$route_collection
->
add
(
'test'
,
$route
);
$event
=
new
RouteBuildEvent
(
$route_collection
,
'test'
);
$this
->
assertFalse
(
$this
->
specialAttributesRouteSubscriber
->
onAlterRoutes
(
$event
)
)
;
$this
->
specialAttributesRouteSubscriber
->
onAlterRoutes
(
$event
);
}
}
}
namespace
{
if
(
!
function_exists
(
'watchdog'
))
{
function
watchdog
(
$type
,
$message
,
array
$args
=
array
())
{
}
}
if
(
!
function_exists
(
'drupal_set_message'
))
{
function
drupal_set_message
(
$type
=
NULL
,
$message
=
''
)
{
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment