Commit ebf26647 authored by jcnventura's avatar jcnventura

Issue #1579176: fix rewrite of empty URL.

parent 331fb669
...@@ -427,7 +427,18 @@ function _print_rewrite_urls($matches) { ...@@ -427,7 +427,18 @@ function _print_rewrite_urls($matches) {
if (preg_match('!^(?:href|src)\s*?=(.*)!i', $attribs[$i], $urls) > 0) { if (preg_match('!^(?:href|src)\s*?=(.*)!i', $attribs[$i], $urls) > 0) {
$url = trim($urls[1], " \t\n\r\0\x0B\"'"); $url = trim($urls[1], " \t\n\r\0\x0B\"'");
if (strpos(html_entity_decode($url), '://') || preg_match('!^mailto:.*?@.*?\..*?$!iu', html_entity_decode($url))) { if (empty($url)) {
// If URL is empty, use current_url
$path = explode('/', $_GET['q']);
unset($path[0]);
$path = implode('/', $path);
if (ctype_digit($path)) {
$path = "node/$path";
}
// Printer-friendly URLs is on, so we need to make it absolute
$newurl = url($path, array('fragment' => drupal_substr($url, 1), 'absolute' => TRUE));
}
elseif (strpos(html_entity_decode($url), '://') || preg_match('!^mailto:.*?@.*?\..*?$!iu', html_entity_decode($url))) {
// URL is absolute, do nothing // URL is absolute, do nothing
$newurl = $url; $newurl = $url;
} }
...@@ -495,7 +506,7 @@ function _print_rewrite_urls($matches) { ...@@ -495,7 +506,7 @@ function _print_rewrite_urls($matches) {
*/ */
function _print_friendly_urls($url = 0) { function _print_friendly_urls($url = 0) {
static $urls = array(); static $urls = array();
if ($url) { if ($url !== 0) {
$url_idx = array_search($url, $urls); $url_idx = array_search($url, $urls);
if ($url_idx !== FALSE) { if ($url_idx !== FALSE) {
return ($url_idx + 1); return ($url_idx + 1);
......
...@@ -55,6 +55,8 @@ class PrintBasicTest extends DrupalWebTestCase { ...@@ -55,6 +55,8 @@ class PrintBasicTest extends DrupalWebTestCase {
// Must require it, since this function gets called via Drupal's dynamic loading // Must require it, since this function gets called via Drupal's dynamic loading
module_load_include('inc', 'print', 'print.pages'); module_load_include('inc', 'print', 'print.pages');
variable_set('print_urls_anchors', 1);
$_print_urls = TRUE; $_print_urls = TRUE;
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is'; $pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
...@@ -95,6 +97,10 @@ class PrintBasicTest extends DrupalWebTestCase { ...@@ -95,6 +97,10 @@ class PrintBasicTest extends DrupalWebTestCase {
$rel_url[9] = $url[9]; $rel_url[9] = $url[9];
$abs_url[9] = $url[9]; $abs_url[9] = $url[9];
$url[10] = '';
$rel_url[10] = '';
$abs_url[10] = $base_url .'/'. $this->getq;
$size = count($url); $size = count($url);
for ($i = 0; $i < $size; $i++) { for ($i = 0; $i < $size; $i++) {
preg_match($pattern, $part1 . $url[$i] . $part2, $matches); preg_match($pattern, $part1 . $url[$i] . $part2, $matches);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment