Commit 06136856 authored by alexpott's avatar alexpott

Issue #2529514 by dawehner, Fabianx, Wim Leers: Replace...

Issue #2529514 by dawehner, Fabianx, Wim Leers: Replace system.filter::protocols with container parameters
parent 0fc922d9
......@@ -7,6 +7,20 @@ parameters:
default: keyvalue.database
factory.keyvalue.expirable:
default: keyvalue.expirable.database
filter_protocols:
- http
- https
- ftp
- news
- nntp
- tel
- telnet
- mailto
- irc
- ssh
- sftp
- webcal
- rtsp
services:
# Simple cache contexts, directly derived from the request context.
cache_context.ip:
......@@ -712,7 +726,7 @@ services:
- { name: event_subscriber }
url_generator.non_bubbling:
class: Drupal\Core\Routing\UrlGenerator
arguments: ['@router.route_provider', '@path_processor_manager', '@route_processor_manager', '@config.factory', '@request_stack']
arguments: ['@router.route_provider', '@path_processor_manager', '@route_processor_manager', '@request_stack', '%filter_protocols%']
public: false
calls:
- [setContext, ['@?router.request_context']]
......@@ -726,7 +740,7 @@ services:
arguments: ['@request_stack', '@url_generator']
unrouted_url_assembler:
class: Drupal\Core\Utility\UnroutedUrlAssembler
arguments: ['@request_stack', '@config.factory', '@path_processor_manager']
arguments: ['@request_stack', '@path_processor_manager', '%filter_protocols%']
link_generator:
class: Drupal\Core\Utility\LinkGenerator
arguments: ['@url_generator', '@module_handler', '@renderer']
......
......@@ -466,8 +466,8 @@ public function preHandle(Request $request) {
$this->container->get('request_stack')->push($request);
// Set the allowed protocols once we have the config available.
$allowed_protocols = $this->container->get('config.factory')->get('system.filter')->get('protocols');
if (!isset($allowed_protocols)) {
$allowed_protocols = $this->container->getParameter('filter_protocols');
if (!$allowed_protocols) {
// \Drupal\Component\Utility\UrlHelper::filterBadProtocol() is called by
// the installer and update.php, in which case the configuration may not
// exist (yet). Provide a minimal default set of allowed protocols for
......
......@@ -72,19 +72,18 @@ class UrlGenerator implements UrlGeneratorInterface {
* The path processor to convert the system path to one suitable for urls.
* @param \Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface $route_processor
* The route processor.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The config factory.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* A request stack object.
* @param string[] $filter_protocols
* (optional) An array of protocols allowed for URL generation.
*/
public function __construct(RouteProviderInterface $provider, OutboundPathProcessorInterface $path_processor, OutboundRouteProcessorInterface $route_processor, ConfigFactoryInterface $config, RequestStack $request_stack) {
public function __construct(RouteProviderInterface $provider, OutboundPathProcessorInterface $path_processor, OutboundRouteProcessorInterface $route_processor, RequestStack $request_stack, array $filter_protocols = ['http', 'https']) {
$this->provider = $provider;
$this->context = new RequestContext();
$this->pathProcessor = $path_processor;
$this->routeProcessor = $route_processor;
$allowed_protocols = $config->get('system.filter')->get('protocols') ?: array('http', 'https');
UrlHelper::setAllowedProtocols($allowed_protocols);
UrlHelper::setAllowedProtocols($filter_protocols);
$this->requestStack = $request_stack;
}
......
......@@ -40,14 +40,13 @@ class UnroutedUrlAssembler implements UnroutedUrlAssemblerInterface {
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* A request stack object.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The config factory.
* @param \Drupal\Core\PathProcessor\OutboundPathProcessorInterface $path_processor
* The output path processor.
* @param string[] $filter_protocols
* (optional) An array of protocols allowed for URL generation.
*/
public function __construct(RequestStack $request_stack, ConfigFactoryInterface $config, OutboundPathProcessorInterface $path_processor) {
$allowed_protocols = $config->get('system.filter')->get('protocols') ?: ['http', 'https'];
UrlHelper::setAllowedProtocols($allowed_protocols);
public function __construct(RequestStack $request_stack, OutboundPathProcessorInterface $path_processor, array $filter_protocols = ['http', 'https']) {
UrlHelper::setAllowedProtocols($filter_protocols);
$this->requestStack = $request_stack;
$this->pathProcessor = $path_processor;
}
......
......@@ -501,7 +501,7 @@ function _filter_url($text, $filter) {
// we cannot cleanly differ between protocols here without hard-coding MAILTO,
// so '//' is optional for all protocols.
// @see \Drupal\Component\Utility\UrlHelper::filterBadProtocol()
$protocols = \Drupal::config('system.filter')->get('protocols');
$protocols = \Drupal::getContainer()->getParameter('filter_protocols') ?: ['http', 'https'];
$protocols = implode(':(?://)?|', $protocols) . ':(?://)?';
$valid_url_path_characters = "[\p{L}\p{M}\p{N}!\*\';:=\+,\.\$\/%#\[\]\-_~@&]";
......
......@@ -594,7 +594,7 @@ function testUrlFilter() {
),
// Absolute URL protocols.
// The list to test is found in the beginning of _filter_url() at
// $protocols = $this->config('system.filter')->get('protocols').
// $protocols = \Drupal::getContainer()->getParameter('filter_protocols').
'
https://example.com,
ftp://ftp.example.com,
......
id: d6_system_filter
label: Drupal 6 filter configuration
migration_tags:
- Drupal 6
source:
plugin: variable
variables:
- filter_allowed_protocols
process:
protocols: filter_allowed_protocols
destination:
plugin: config
config_name: system.filter
......@@ -121,7 +121,6 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase {
'd6_syslog_settings',
'd6_system_cron',
'd6_system_file',
'd6_system_filter',
'd6_system_image',
'd6_system_image_gd',
'd6_system_logging',
......
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateSystemFilterTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* Upgrade filter variables to system.*.yml.
*
* @group migrate_drupal
*/
class MigrateSystemFilterTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->loadDumps(['Variable.php']);
$this->executeMigration('d6_system_filter');
}
/**
* Tests migration of system (filter) variables to system.filter.yml.
*/
public function testSystemFilter() {
$config = $this->config('system.filter');
$this->assertIdentical(array('http', 'https', 'ftp', 'news', 'nntp', 'tel', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal', 'rtsp'), $config->get('protocols'));
}
}
protocols:
- http
- https
- ftp
- news
- nntp
- tel
- telnet
- mailto
- irc
- ssh
- sftp
- webcal
- rtsp
......@@ -126,17 +126,6 @@ system.diff:
type: integer
label: 'Number of trailing lines in a diff'
system.filter:
type: config_object
label: 'Filter settings'
mapping:
protocols:
type: sequence
label: 'Allowed protocols'
sequence:
type: string
label: 'Protocol'
system.logging:
type: config_object
label: 'Logging settings'
......
......@@ -168,16 +168,8 @@ protected function setUp() {
* Sets up the unrouted url assembler and the link generator.
*/
protected function setUpUrlIntegrationServices() {
$config = $this->getMockBuilder('Drupal\Core\Config\ImmutableConfig')
->disableOriginalConstructor()
->getMock();
$config_factory = $this->getMock('\Drupal\Core\Config\ConfigFactoryInterface');
$config_factory->expects($this->any())
->method('get')
->willReturn($config);
$this->pathProcessor = $this->getMock('Drupal\Core\PathProcessor\OutboundPathProcessorInterface');
$this->unroutedUrlAssembler = new UnroutedUrlAssembler($this->requestStack, $config_factory, $this->pathProcessor);
$this->unroutedUrlAssembler = new UnroutedUrlAssembler($this->requestStack, $this->pathProcessor);
\Drupal::getContainer()->set('unrouted_url_assembler', $this->unroutedUrlAssembler);
......
......@@ -147,9 +147,7 @@ protected function setUp() {
->disableOriginalConstructor()
->getMock();
$config_factory_stub = $this->getConfigFactoryStub(array('system.filter' => array('protocols' => array('http', 'https'))));
$generator = new UrlGenerator($provider, $processor_manager, $this->routeProcessorManager, $config_factory_stub, $this->requestStack);
$generator = new UrlGenerator($provider, $processor_manager, $this->routeProcessorManager, $this->requestStack, ['http', 'https']);
$generator->setContext($context);
$this->generator = $generator;
}
......
......@@ -55,9 +55,8 @@ protected function setUp() {
parent::setUp();
$this->requestStack = new RequestStack();
$this->configFactory = $this->getConfigFactoryStub(['system.filter' => []]);
$this->pathProcessor = $this->getMock('Drupal\Core\PathProcessor\OutboundPathProcessorInterface');
$this->unroutedUrlAssembler = new UnroutedUrlAssembler($this->requestStack, $this->configFactory, $this->pathProcessor);
$this->unroutedUrlAssembler = new UnroutedUrlAssembler($this->requestStack, $this->pathProcessor);
}
/**
......
......@@ -96,3 +96,18 @@ parameters:
# Default key/value expirable storage service to use.
# @default keyvalue.database.expirable
# default: keyvalue.database.expirable
# Allowed protocols for URL generation.
filter_protocols:
- http
- https
- ftp
- news
- nntp
- tel
- telnet
- mailto
- irc
- ssh
- sftp
- webcal
- rtsp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment