Skip to content
Snippets Groups Projects
Commit 4b48257d authored by Garrett Albright's avatar Garrett Albright
Browse files

Fix paths of just a slash - [#817722] sort of

parent 54c13c66
No related branches found
No related tags found
No related merge requests found
......@@ -86,12 +86,13 @@ function _pathologic($text, $filter) {
// The pattern is gonna look like:
// ~(href|src|HREF|SRC)="(
// (
// /|
// (internal:|https?://example\.com|https?://example\.org)(/?(index\.php)?(\?q=)?)|
// (?!([#/]|mailto:|.*:/))(internal:|\?q=)?
// (?!([#/]|mailto:|.*:/))(\?q=)?
// )
// ([^"]*)
// )~
'pattern' => '~(href|src|HREF|SRC)="(((internal:|' . implode('|', $paths) . ')(/?(index.php)?(\?q=)?)|(?!([#/]|mailto:|.*:/))(\?q=)?)([^"]*))~',
'pattern' => '~(href|src|HREF|SRC)="((/|(internal:|' . implode('|', $paths) . ')(/?(index.php)?(\?q=)?)|(?!([#/]|mailto:|.*:/))(\?q=)?)([^"]*))~',
// create_funtion() lets us do lambdas in a really crappy but pre-PHP 5.3-
// compatible way. We're using it here so we can pass the value of
// $filter->settings['absolute'] to the replacement function. We could
......@@ -121,7 +122,7 @@ function _pathologic_replace($matches, $absolute) {
// the path is just one character (just '/'), but url() seems to be okay with
// that.
$parts['path'] = drupal_substr($parts['path'], 1);
// Need to parse the query parts
if (isset($parts['query'])) {
parse_str($parts['query'], $qparts);
......
......@@ -44,6 +44,7 @@ class PathologicTestCase extends DrupalWebTestCase {
drupal_static_reset('filter_formats');
// Build some paths to check against
$paths = array(
'front' => url('<front>', array('absolute' => TRUE)),
'admin' => url('admin', array('absolute' => TRUE)),
'foo' => url('foo', array('absolute' => TRUE)),
'foo/bar' => url('foo/bar', array('absolute' => TRUE)),
......@@ -66,11 +67,13 @@ class PathologicTestCase extends DrupalWebTestCase {
$this->assertEqual(check_markup('<a href="internal:foo"><img src="internal:foo/bar?baz=qux"></a>', 4), '<a href="' . $paths['foo'] . '"><img src="' . $paths['foo/bar?baz=qux'] . '"></a>', t('Path Filter back compatibility'));
// Also considered local
$this->assertEqual(check_markup('<a href="http://example.com/foo"><img src="http://example.com/index.php?q=foo/bar&baz=qux"></a>', 4), '<a href="' . $paths['foo'] . '"><img src="' . $paths['foo/bar?baz=qux'] . '"></a>', t('Also considered local'));
// Asterisks local paths
// Asterisks in domain names - [#758118]
$this->assertEqual(check_markup('<a href="http://foo.example.net/foo"><img src="http://example.org/qux/bar/foo"></a>', 4), '<a href="' . $paths['foo'] . '"><img src="' . $paths['foo'] . '"></a>', t('Asterisk in domain'));
// Non-absolute - Note we're using format 5 here
$this->assertEqual(check_markup('<a href="?q=quuux"><img src="quuux"></a>', 5), '<a href="' . $paths['quuux'] . '"><img src="' . $paths['quuux'] . '"></a>', t('Non-absolute path output'));
// Upper-case HREF and SRC params - [#760876]
$this->assertEqual(check_markup('<A HREF="foo"><IMG SRC="foo/bar"></A>', 4), '<A HREF="' . $paths['foo'] . '"><IMG SRC="' . $paths['foo/bar'] . '"></A>', t('Old-skool upper-case attribute names'));
// Paths with just slashes - [#817722] sort of
$this->assertEqual(check_markup('<a href="/"></a>', 4), '<a href="' . $paths['front'] . '"></a>', t('Linking to front page with href="/"'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment