setAllowedProtocols example


  public function testFilterBadProtocol($uri$expected$protocols) {
    UrlHelper::setAllowedProtocols($protocols);
    $this->assertEquals($expected, UrlHelper::filterBadProtocol($uri));
    // Multiple calls to UrlHelper::filterBadProtocol() do not cause double     // escaping.     $this->assertEquals($expected, UrlHelper::filterBadProtocol(UrlHelper::filterBadProtocol($uri)));
  }

  /** * Provides data for self::testTestFilterBadProtocol(). * * @return array */
  
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($link$constraint);
  }

  /** * Data provider for ::testValidate. */
  
'ftp',
      'news',
      'nntp',
      'telnet',
      'mailto',
      'irc',
      'ssh',
      'sftp',
      'webcal',
      'rtsp',
    ];
    UrlHelper::setAllowedProtocols($allowed_protocols);
  }

  /** * Tests limiting allowed tags and XSS prevention. * * XSS tests assume that script is disallowed by default and src is allowed * by default, but on* and style attributes are disallowed. * * @param string $value * The value to filter. * @param string $expected * The expected result. * @param string $message * The assertion message to display upon failure. * @param array $allowed_tags * (optional) The allowed HTML tags to be passed to \Drupal\Component\Utility\Xss::filter(). * * @dataProvider providerTestFilterXssNormalized */

  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;
  }

  /** * {@inheritdoc} * * phpcs:ignore Drupal.Commenting.FunctionComment.VoidReturn * @return void */
  public function setContext(SymfonyRequestContext $context) {
    $this->context = $context;
  }
// 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'));

    $this->prepared = TRUE;
  }

  /** * {@inheritdoc} */
  public function discoverServiceProviders() {
    $this->serviceYamls = [
      'app' => [],
      'site' => [],
    ];
/** * 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;
  }

  /** * {@inheritdoc} * * This is a helper function that calls buildExternalUrl() or buildLocalUrl() * based on a check of whether the path is a valid external URL. */
  public function assemble($uri, array $options = []$collect_bubbleable_metadata = FALSE) {
    
Home | Imprint | This part of the site doesn't use cookies.