Commit dd804bc2 authored by Derek Wright's avatar Derek Wright
Browse files

Issue #3027696 by dww, spleenboy: hook_pathologic_alter external option doesn't work

parent cb080a7b
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -325,7 +325,8 @@ function _pathologic_replace($matches) {
  $url_params = [
    'path' => $parts['path'],
    'options' => [
      'query' => $parts['qparts'],
      // Force the query to an array if it's unspecified.
      'query' => $parts['qparts'] ?: [],
      'path_processing' => TRUE,
      'fragment' => isset($parts['fragment']) ? $parts['fragment'] : NULL,
      // Create an absolute URL if protocol_style is 'full' or 'proto-rel', but
@@ -359,9 +360,9 @@ function _pathologic_replace($matches) {
    $url = Url::fromRoute('<front>', [], $url_params['options'])->toString();
  }
  else {
    $path = (empty($url_params['options']['external']) ? 'base:/' : '') . $url_params['path'];
    try {
      $url = Url::fromUri('base:/' . $url_params['path'], $url_params['options'])
        ->toString();
      $url = Url::fromUri($path, $url_params['options'])->toString();
    }
    catch (\Exception $e) {
      // In case of an error, e.g. completely invalid URL, return it unchanged.
+4 −0
Original line number Diff line number Diff line
@@ -15,5 +15,9 @@ function pathologic_test_pathologic_alter(&$url_params, $parts, $settings) {
    elseif ($parts['qparts']['test'] === 'use_original') {
      $url_params['options']['use_original'] = TRUE;
    }
    elseif ($parts['qparts']['test'] === 'external') {
      $url_params['path'] = 'http://cdn.example.com/' . $url_params['path'];
      $url_params['options']['external'] = TRUE;
    }
  }
}
+4 −0
Original line number Diff line number Diff line
@@ -217,6 +217,10 @@ class PathologicTest extends BrowserTestBase {
      '<a href="bar?test=use_original">',
      t('hook_pathologic_alter(): Passthrough with use_original option')
    );
    $this->assertEquals(
      check_markup('<a href="bar?test=external">', $format_id),
      '<a href="http://cdn.example.com/bar?test=external">',
    );

    // Test paths to existing files when clean URLs are disabled.
    // @see http://drupal.org/node/1672430