diff --git a/pathologic.module b/pathologic.module
index 87ffd26..bb91c94 100644
--- a/pathologic.module
+++ b/pathologic.module
@@ -136,56 +136,18 @@ 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();
- if ($filter_settings['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
- $local_paths = array_filter(array_map('trim', explode("\n", $filter_settings['local_paths'])));
- foreach ($local_paths as $local) {
- $parts = @parse_url($local);
- // Okay, what the hellish "if" statement is doing below is checking to
- // make sure we aren't about to add a path to our array of exploded
- // local paths which matches the current "local" path. We consider it
- // not a match, if…
- // @todo: This is pretty horrible. Can this be simplified?
- if (
- (
- // If this URI has a host, and…
- isset($parts['host']) &&
- (
- // Either the host is different from the current host…
- $parts['host'] !== $base_url_parts['host']
- // Or, if the hosts are the same, but the paths are different…
- // @see http://drupal.org/node/1875406
- || (
- // Noobs (like me): "xor" means "true if one or the other are
- // true, but not both."
- (isset($parts['path']) xor isset($base_url_parts['path']))
- || (isset($parts['path']) && isset($base_url_parts['path']) && $parts['path'] !== $base_url_parts['path'])
- )
- )
- ) ||
- // Or…
- (
- // The URI doesn't have a host…
- !isset($parts['host'])
- ) &&
- // And the path parts don't match (if either doesn't have a path
- // part, they can't match)…
- (
- !isset($parts['path']) ||
- !isset($base_url_parts['path']) ||
- $parts['path'] !== $base_url_parts['path']
- )
- ) {
- // Add it to the list.
- $filter_settings['local_paths_exploded'][] = $parts;
- }
- }
+ $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;
}
- // Now add local paths based on "this" server URL.
+ // 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']);
// We'll also just store the host part separately for easy access.
diff --git a/tests/pathologic.test b/tests/pathologic.test
index 2e62320..21974c2 100644
--- a/tests/pathologic.test
+++ b/tests/pathologic.test
@@ -227,6 +227,29 @@ class PathologicTestCase extends DrupalWebTestCase {
'',
t('Use global settings when so configured on the format')
);
+
+ // Test local paths where one is being a sub path of another.
+ // @see https://drupal.org/node/2545396.
+ // Fake that we are running on the test environment on a sub directory test.
+ $base_path_org = $base_path;
+ $base_url_org = $base_url;
+ $base_path .= 'test/';
+ $base_url .= '/test';
+ $format_id = _pathologic_build_format(array(
+ 'protocol_style' => 'path',
+ 'local_paths' => "/test/\n/\n",
+ 'settings_source' => 'local',
+ ));
+
+ $this->assertEqual(
+ check_markup('bar', $format_id),
+ 'bar',
+ "Local paths where one is being a sub path of another"
+ );
+
+ // Restore $base_path and $base_url.
+ $base_path .= $base_path_org;
+ $base_url .= $base_url_org;
}
}