예제 #1
0
 /**
  *  Constructs a new unroutedUrlAssembler object.
  *
  * @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.
  */
 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);
     $this->requestStack = $request_stack;
     $this->pathProcessor = $path_processor;
 }
예제 #2
0
 /**
  * Constructs a new generator object.
  *
  * @param \Drupal\Core\Routing\RouteProviderInterface $provider
  *   The route provider to be searched for routes.
  * @param \Drupal\Core\PathProcessor\OutboundPathProcessorInterface $path_processor
  *   The path processor to convert the system path to one suitable for urls.
  * @param \Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface $route_processor
  *   The route processor.
  * @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, RequestStack $request_stack, array $filter_protocols = ['http', 'https'])
 {
     $this->provider = $provider;
     $this->context = new RequestContext();
     $this->pathProcessor = $path_processor;
     $this->routeProcessor = $route_processor;
     UrlHelper::setAllowedProtocols($filter_protocols);
     $this->requestStack = $request_stack;
 }
예제 #3
0
 /**
  *  Constructs a new generator object.
  *
  * @param \Drupal\Core\Routing\RouteProviderInterface $provider
  *   The route provider to be searched for routes.
  * @param \Drupal\Core\PathProcessor\OutboundPathProcessorInterface $path_processor
  *   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 \Psr\Log\LoggerInterface $logger
  *   An optional logger for recording errors.
  * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
  *   A request stack object.
  */
 public function __construct(RouteProviderInterface $provider, OutboundPathProcessorInterface $path_processor, OutboundRouteProcessorInterface $route_processor, ConfigFactoryInterface $config, LoggerInterface $logger = NULL, RequestStack $request_stack)
 {
     parent::__construct($provider, $logger);
     $this->pathProcessor = $path_processor;
     $this->routeProcessor = $route_processor;
     $allowed_protocols = $config->get('system.filter')->get('protocols') ?: array('http', 'https');
     UrlHelper::setAllowedProtocols($allowed_protocols);
     $this->requestStack = $request_stack;
 }
 /**
  * @covers ::validate
  * @dataProvider providerValidate
  */
 public function testValidate($value, $valid)
 {
     $context = $this->getMock('Symfony\\Component\\Validator\\ExecutionContextInterface');
     if ($valid) {
         $context->expects($this->never())->method('addViolation');
     } else {
         $context->expects($this->once())->method('addViolation');
     }
     // Setup some more allowed protocols.
     UrlHelper::setAllowedProtocols(['http', 'https', 'magnet']);
     $constraint = new LinkExternalProtocolsConstraint();
     $validator = new LinkExternalProtocolsConstraintValidator();
     $validator->initialize($context);
     $validator->validate($value, $constraint);
 }
 /**
  * Constructs a new unroutedUrlAssembler object.
  *
  * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
  *   A request stack object.
  * @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, OutboundPathProcessorInterface $path_processor, array $filter_protocols = ['http', 'https'])
 {
     UrlHelper::setAllowedProtocols($filter_protocols);
     $this->requestStack = $request_stack;
     $this->pathProcessor = $path_processor;
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function preHandle(Request $request)
 {
     $this->loadLegacyIncludes();
     // Load all enabled modules.
     $this->container->get('module_handler')->loadAll();
     // Register stream wrappers.
     $this->container->get('stream_wrapper_manager')->register();
     // Initialize legacy request globals.
     $this->initializeRequestGlobals($request);
     // Put the request on the stack.
     $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)) {
         // \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
         // these cases.
         $allowed_protocols = array('http', 'https');
     }
     UrlHelper::setAllowedProtocols($allowed_protocols);
     // Override of Symfony's mime type guesser singleton.
     MimeTypeGuesser::registerWithSymfonyGuesser($this->container);
     $this->prepared = TRUE;
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function preHandle(Request $request)
 {
     $this->loadLegacyIncludes();
     // Load all enabled modules.
     $this->container->get('module_handler')->loadAll();
     // Register stream wrappers.
     $this->container->get('stream_wrapper_manager')->register();
     // Initialize legacy request globals.
     $this->initializeRequestGlobals($request);
     // Put the request on the stack.
     $this->container->get('request_stack')->push($request);
     // Set the allowed protocols.
     UrlHelper::setAllowedProtocols($this->container->getParameter('filter_protocols'));
     // Override of Symfony's MIME type guesser singleton.
     MimeTypeGuesser::registerWithSymfonyGuesser($this->container);
     $this->prepared = TRUE;
 }
예제 #8
0
 /**
  * Tests dangerous url protocol filtering.
  *
  * @dataProvider providerTestStripDangerousProtocols
  * @covers ::setAllowedProtocols
  * @covers ::stripDangerousProtocols
  *
  * @param string $uri
  *    Protocol URI.
  * @param string $expected
  *    Expected escaped value.
  * @param array $protocols
  *    Protocols to allow.
  */
 public function testStripDangerousProtocols($uri, $expected, $protocols)
 {
     UrlHelper::setAllowedProtocols($protocols);
     $stripped = UrlHelper::stripDangerousProtocols($uri);
     $this->assertEquals($expected, $stripped);
 }
 /**
  * {@inheritdoc}
  */
 public function preHandle(Request $request)
 {
     // Load all enabled modules.
     $this->container->get('module_handler')->loadAll();
     // Initialize legacy request globals.
     $this->initializeRequestGlobals($request);
     // Initialize cookie globals.
     $this->initializeCookieGlobals($request);
     // Put the request on the stack.
     $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)) {
         // \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
         // these cases.
         $allowed_protocols = array('http', 'https');
     }
     UrlHelper::setAllowedProtocols($allowed_protocols);
 }
예제 #10
0
파일: XssTest.php 프로젝트: brstde/gap1
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $allowed_protocols = array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal', 'rtsp');
     UrlHelper::setAllowedProtocols($allowed_protocols);
 }
예제 #11
0
  /**
   * Tests string formatting with SafeMarkup::format().
   *
   * @dataProvider providerFormat
   * @covers ::format
   *
   * @param string $string
   *   The string to run through SafeMarkup::format().
   * @param string[] $args
   *   The arguments to pass into SafeMarkup::format().
   * @param string $expected
   *   The expected result from calling the function.
   * @param string $message
   *   The message to display as output to the test.
   * @param bool $expected_is_safe
   *   Whether the result is expected to be safe for HTML display.
   */
  public function testFormat($string, array $args, $expected, $message, $expected_is_safe) {
    UrlHelper::setAllowedProtocols(['http', 'https', 'mailto']);

    $result = SafeMarkup::format($string, $args);
    $this->assertEquals($expected, $result, $message);
    $this->assertEquals($expected_is_safe, SafeMarkup::isSafe($result), 'SafeMarkup::format correctly sets the result as safe or not safe.');

    foreach ($args as $arg) {
      $this->assertSame($arg instanceof SafeMarkupTestMarkup, SafeMarkup::isSafe($arg));
    }
  }
예제 #12
0
 /**
  *  Constructs a new generator object.
  *
  * @param \Drupal\Core\Routing\RouteProviderInterface $provider
  *   The route provider to be searched for routes.
  * @param \Drupal\Core\PathProcessor\OutboundPathProcessorInterface $path_processor
  *   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 \Drupal\Core\Site\Settings $settings
  *    The read only settings.
  * @param \Psr\Log\LoggerInterface $logger
  *   An optional logger for recording errors.
  * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
  *   A request stack object.
  */
 public function __construct(RouteProviderInterface $provider, OutboundPathProcessorInterface $path_processor, OutboundRouteProcessorInterface $route_processor, ConfigFactoryInterface $config, Settings $settings, LoggerInterface $logger = NULL, RequestStack $request_stack)
 {
     parent::__construct($provider, $logger);
     $this->pathProcessor = $path_processor;
     $this->routeProcessor = $route_processor;
     $this->mixedModeSessions = $settings->get('mixed_mode_sessions', FALSE);
     $allowed_protocols = $config->get('system.filter')->get('protocols') ?: array('http', 'https');
     UrlHelper::setAllowedProtocols($allowed_protocols);
     $this->requestStack = $request_stack;
     $this->updateFromRequest();
 }