Commit b96f896f authored by John Fiala's avatar John Fiala
Browse files

Issue #1043348 by jcfiala:First pass at fixing problems with raw...

Issue #1043348 by jcfiala:First pass at fixing problems with raw www.example.com urls ending up as index.php?q=www.example.com.  Need more testing/fixing with fragments and querystrings - not complete.
parent 4a7b4601
...@@ -360,6 +360,8 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$node) { ...@@ -360,6 +360,8 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$node) {
$type = link_validate_url($item['url']); $type = link_validate_url($item['url']);
$url = link_cleanup_url($item['url']); $url = link_cleanup_url($item['url']);
//dpm(array($type, $url));
// Separate out the anchor if any. // Separate out the anchor if any.
if (strpos($url, '#') !== FALSE) { if (strpos($url, '#') !== FALSE) {
...@@ -373,6 +375,7 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$node) { ...@@ -373,6 +375,7 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$node) {
$item['query'] = $query_array; $item['query'] = $query_array;
$url = substr($url, 0, strpos($url, '?')); $url = substr($url, 0, strpos($url, '?'));
} }
$item['url'] = check_plain($url);
// Create a shortened URL for display. // Create a shortened URL for display.
$display_url = $type == LINK_EMAIL ? $display_url = $type == LINK_EMAIL ?
...@@ -642,16 +645,19 @@ function link_field_formatter_view($entity_type, $entity, $field, $instance, $la ...@@ -642,16 +645,19 @@ function link_field_formatter_view($entity_type, $entity, $field, $instance, $la
* Theme function for 'default' text field formatter. * Theme function for 'default' text field formatter.
*/ */
function theme_link_formatter_default($vars) { function theme_link_formatter_default($vars) {
$link_options = $vars['element'];
unset($link_options['element']['title']);
unset($link_options['element']['url']);
// Display a normal link if both title and URL are available. // Display a normal link if both title and URL are available.
if (!empty($vars['element']['title']) && !empty($vars['element']['url'])) { if (!empty($vars['element']['title']) && !empty($vars['element']['url'])) {
return l($vars['element']['title'], $vars['element']['url'], array('attributes' => $vars['element']['attributes'])); return l($vars['element']['title'], $vars['element']['url'], $link_options);
} }
// If only a title, display the title. // If only a title, display the title.
elseif (!empty($vars['element']['title'])) { elseif (!empty($vars['element']['title'])) {
return check_plain($vars['element']['title']); return check_plain($vars['element']['title']);
} }
elseif (!empty($vars['element']['url'])) { elseif (!empty($vars['element']['url'])) {
return l($vars['element']['title'], $vars['element']['url'], array('attributes' => $vars['element']['attributes'])); return l($vars['element']['title'], $vars['element']['url'], $link_options);
} }
} }
......
...@@ -121,6 +121,15 @@ class LinkUITest extends DrupalWebTestcase { ...@@ -121,6 +121,15 @@ class LinkUITest extends DrupalWebTestcase {
'type' => self::LINK_INPUT_TYPE_BAD_URL 'type' => self::LINK_INPUT_TYPE_BAD_URL
), ),
); );
$test_case = array(
'href' => 'www.example.com/'. $this->randomName(),
'label' => $this->randomName(),
'msg' => 'Link found',
'type' => self::LINK_INPUT_TYPE_GOOD,
);
$test_case['expected_href'] = 'http://'. $test_case['href'];
$input_test_cases[] = $test_case;
foreach ($input_test_cases as $input) { foreach ($input_test_cases as $input) {
$this->drupalLogin($account); $this->drupalLogin($account);
$this->drupalGet('node/add/page'); $this->drupalGet('node/add/page');
...@@ -150,7 +159,12 @@ class LinkUITest extends DrupalWebTestcase { ...@@ -150,7 +159,12 @@ class LinkUITest extends DrupalWebTestcase {
// If simpletest starts using something to override the error system, this will flag // If simpletest starts using something to override the error system, this will flag
// us and let us know it's broken. // us and let us know it's broken.
$this->assertFalse(libxml_use_internal_errors(TRUE)); $this->assertFalse(libxml_use_internal_errors(TRUE));
$path = '//a[@href="'. $input['href'] .'" and text()="'. $input['label'] .'"]'; if (isset($input['expected_href'])) {
$path = '//a[@href="'. $input['expected_href'] .'" and text()="'. $input['label'] .'"]';
}
else {
$path = '//a[@href="'. $input['href'] .'" and text()="'. $input['label'] .'"]';
}
//$this->pass(htmlentities($path)); //$this->pass(htmlentities($path));
$elements = $this->xpath($path); $elements = $this->xpath($path);
libxml_use_internal_errors(FALSE); libxml_use_internal_errors(FALSE);
...@@ -314,7 +328,7 @@ class LinkUITest extends DrupalWebTestcase { ...@@ -314,7 +328,7 @@ class LinkUITest extends DrupalWebTestcase {
$this->drupalLogout(); $this->drupalLogout();
$this->drupalGet($url); $this->drupalGet($url);
$this->assertRaw(l('<strong>'. $name .'</strong>', $input['href'], array('html' => FALSE))); $this->assertRaw(l('<strong>'. $name .'</strong>', $input['href'], array('html' => TRUE)));
} }
/** /**
......
Supports Markdown
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