diff --git a/pathologic.module b/pathologic.module index bb91c94..61a1c2d 100644 --- a/pathologic.module +++ b/pathologic.module @@ -136,20 +136,32 @@ function _pathologic_filter($text, $filter, $format, $langcode, $cache, $cache_i $filter_settings['protocol_style'] = variable_get('pathologic_protocol_style', 'full'); $filter_settings['local_paths'] = variable_get('pathologic_local_paths', ''); } - // Build an array of the exploded local paths for this format's settings. - // array_filter() below is filtering out items from the array which equal - // FALSE - so empty strings (which were causing problems, - // @see http://drupal.org/node/1727492) - $filter_settings['local_paths_exploded'] = array(); + // Build an array of the local paths containing: + // -1- The paths from this format's setting "Also considered local". Note + // that array_filter() below is filtering out empty items from the array + // as per issue [#1727492]. $local_paths = array_filter(array_map('trim', explode("\n", $filter_settings['local_paths']))); - foreach ($local_paths as $local) { - $parts = @parse_url($local); - $filter_settings['local_paths_exploded'][] = $parts; + // -2- The actual local path in both formats \path\ and \\host\path\, and as + // far as not already added. + $local_paths[] = $base_url_parts['path']; + $local_paths[] = '//'. $base_url_parts['host'] . $base_url_parts['path']; + $local_paths = array_unique($local_paths); + + // Build an array of the exploded local paths. + $filter_settings['local_paths_exploded'] = array(); + foreach ($local_paths as $local_path) { + $filter_settings['local_paths_exploded'][] = @parse_url($local_path); } - // To be sure, now add local paths based on "this" server URL, even if they - // may already have been added above. - $filter_settings['local_paths_exploded'][] = array('path' => $base_url_parts['path']); - $filter_settings['local_paths_exploded'][] = array('path' => $base_url_parts['path'], 'host' => $base_url_parts['host']); + // This array needs an order on the path part: sub paths must come before + // parent paths to prevent that a match on the parent path prevails on a + // match on the sub path, see issue [#2545396]. + // Ordering on descending path length will assure this order. + usort($filter_settings['local_paths_exploded'], function($a, $b) { + $lenA = isset($a['path']) ? drupal_strlen($a['path']) : 0; + $lenB = isset($b['path']) ? drupal_strlen($b['path']) : 0; + return $lenB - $lenA; + }); + // We'll also just store the host part separately for easy access. $filter_settings['base_url_host'] = $base_url_parts['host']; diff --git a/tests/pathologic.test b/tests/pathologic.test index 21974c2..c1c3cdd 100644 --- a/tests/pathologic.test +++ b/tests/pathologic.test @@ -248,8 +248,8 @@ class PathologicTestCase extends DrupalWebTestCase { ); // Restore $base_path and $base_url. - $base_path .= $base_path_org; - $base_url .= $base_url_org; + $base_path = $base_path_org; + $base_url = $base_url_org; } }