- Create a node with a URL field
- Fill in http://www.tralala.com
- When the actual link is clicked, it links to http://http//www.tralala.com while the text shows http://www.tralala.com
- If on the other hand www.tralala.com is filled in as URL
- The link links to http://www.tralala.com and the text shows www.tralala.com

The desired behaviour would be that the link would always links to http://www.tralala.com and that the text shows what the user has entered. So if a http:// is present, keep it, if it is not add it.

Comments

robclay’s picture

There is a URL Link field? How do I create that?

alicia’s picture

I agree this is a problem. It's a hassle to explain to people that they should strip the http:// from their link since that's already hardcoded into the flexinode URL field. Since most people are copying and pasting links directly from their browsers, this shouldn't be the default behavior.

Anonymous’s picture

Its not even that. The input filter for this field is doing some strange validity testing. If you actually enter a proper URL, it passes the validity check and creates a bad link. If you enter the abbreviated reference (omitting http://) it flags the field as being invalid.

In fact, what it should be doing is accepting any valid URL (including non-http URLs) and then normalizing internal references to the Drupal site.

czarphanguye’s picture

Temp fix...

locate field_url.inc

I just commented out the 'verification' checks and also removed the 'http://' (causes users to HAVE TO place http://www.example.com in the url field).

// function flexinode_field_url_validate($field, $node) {
//   $fieldname = 'flexinode_'. $field->field_id;

  // If the URL is empty, or it validates as an absolute URL, or it validates
  // as a relative URL, the URL is considered valid.
 //  if (empty($node->$fieldname) || valid_url($node->$fieldname, true) || valid_url($node->$fieldname)) {
 //    return array('value' => $node->$fieldname);
 //  } 

  // If none of the above was true, the URL is invalid.
  // return array('value' => $node->$fieldname, 'error' => t('The url is not valid.'));
// }

function flexinode_field_url_format($field, $node, $brief = 0) {
  $fieldname = 'flexinode_'. $field->field_id;
  $output = drupal_specialchars($node->$fieldname);
  return $output ? '<a href="'. $output .'">'. $output .'</a>' : '';
}
mcd’s picture

StatusFileSize
new1.07 KB

I noticed this problem as well. Thanks for pointing out the validation problems. A patch for the changes above is attached.

syscrusher’s picture

StatusFileSize
new615 bytes

Here is a patch to the CVS version that does not require disabling the validation. This allows users to enter URLs in any of the following formats (assuming the local site is "http://example.com/":

* A Drupal URL, e.g., "node/123", which will link as "http://example.com/node/123"
* An absolute local URL, e.g., "/somedir/bozon.php", which will link as "http://example.com/somedir/bozon.php"
* An absolute URL, e.g., "http://www.example.org/blah/abc.html", which will link exactly as shown.
* An absolute URL with a different protocol spec, such as "ftp://ftp.example.com/pub/myfile.tgz", which links exactly as shown.

***BEGIN PATCH***
--- field_url.inc 2005-03-26 16:14:50.513087708 -0500
+++ field_url.inc.new 2005-03-26 16:13:17.292388394 -0500
@@ -40,7 +40,10 @@
function flexinode_field_url_format($field, $node, $brief = 0) {
$fieldname = 'flexinode_'. $field->field_id;
$output = drupal_specialchars($node->$fieldname);
- return $output ? ''. $output .'' : '';
+ if (strlen($output) && ! preg_match('%^(\w+://|\w*/)%',$output)) {
+ $output = 'http://' . $output;
+ }
+ return $output ? ''. $output .'' : '';
}

function flexinode_field_url_config($field, $edit) {
***END PATCH***

For those who wish to examine this in a more readable format, here is the old and new code for the entire function:

***OLD***
function flexinode_field_url_format($field, $node, $brief = 0) {
$fieldname = 'flexinode_'. $field->field_id;
$output = drupal_specialchars($node->$fieldname);
return $output ? ''. $output .'' : '';
}
***END OLD***

***NEW***
function flexinode_field_url_format($field, $node, $brief = 0) {
$fieldname = 'flexinode_'. $field->field_id;
$output = drupal_specialchars($node->$fieldname);
if (strlen($output) && ! preg_match('%^(\w+://|\w*/)%',$output)) {
$output = 'http://' . $output;
}
return $output ? ''. $output .'' : '';
}
***END NEW***

I will attach the patch file to this update as well.

syscrusher’s picture

StatusFileSize
new615 bytes

*** ARGH! My previous attempt to post this, I forgot to escape the HTML tags inside the code. Sorry! ***

Here is a patch to the CVS version that does not require disabling the validation. This allows users to enter URLs in any of the following formats (assuming the local site is "http://example.com/"):

***BEGIN PATCH***

--- field_url.inc       2005-03-26 16:14:50.513087708 -0500
+++ field_url.inc.new   2005-03-26 16:13:17.292388394 -0500
@@ -40,7 +40,10 @@
 function flexinode_field_url_format($field, $node, $brief = 0) {
   $fieldname = 'flexinode_'. $field->field_id;
   $output = drupal_specialchars($node->$fieldname);
-  return $output ? '<a href="http://'. $output .'">'. $output .'</a> : '';
+  if (strlen($output) && ! preg_match('%^(\w+://|\w*/)%',$output)) {
+  $output = 'http://' . $output;
+  }
+  return $output ? '<a href="'. $output .'">'. $output .'</a>' : '';
 }

 function flexinode_field_url_config($field, $edit) {

***END PATCH***

For those who wish to examine this in a more readable format, here is the old and new code for the entire function:

***OLD***

function flexinode_field_url_format($field, $node, $brief = 0) {
  $fieldname = 'flexinode_'. $field->field_id;
  $output = drupal_specialchars($node->$fieldname);
  return $output ? '<a href="http://'. $output .'">'. $output .'</a>' : '';
}

***NEW***

function flexinode_field_url_format($field, $node, $brief = 0) {
  $fieldname = 'flexinode_'. $field->field_id;
  $output = drupal_specialchars($node->$fieldname);
  if (strlen($output) && ! preg_match('%^(\w+://|\w*/)%',$output)) {
    $output = 'http://' . $output;
  }
  return $output ? '<a href="'. $output .'">'. $output .'</a>' : '';
}

I will attach the patch file to this update as well.

MJoyce-1’s picture

I'm getting this utl link problem and I think I'm using a later version.
$Id: flexinode.module,v 1.46.2.2 2005/05/02 16:37:16 JonBob Exp $

Should these fixes be rolled into v4.6 ?

boris mann’s picture

This patch has still not been applied to the 4.5 version.

laura s’s picture

Version: » 4.6.x-1.x-dev

This problem persists in version 4.6, the tarball of which still dates to May 2.

As a temporary fix, I'll try the manual disabling of the verification. But as this is a rapidly growing community site I'm having this problem with, I hope the either/or patch is coded for 4.6 soon.

Thanks.

mzabala’s picture

4.6+ version of field_URL.inc

function flexinode_field_url_format($field, $node, $brief = 0) {
  $fieldname = 'flexinode_'. $field->field_id;
  $output = check_plain($node->$fieldname);
  if (strlen($output) && ! preg_match('%^(\w+://|\w*/)%',$output)) {
    $output = 'http://' . $output;
  }
  return $output ? '<a href="'. $output .'">'. $output .'</a>' : '';
}

tested on Civicspace 0.8.1

dww’s picture

StatusFileSize
new915 bytes

comment #11 forgot to include the "<a href" part, so links weren't clickable. here's another version of flexinode_field_url_format for 4.6.0 flexinode (patch to contrib/field_url.inc included) based on the above suggestions but that provides working links. also, my copy preserves what the user specified as the thing that's displayed, while the underlying URL has the proper "http://" to work. so, if they input "www.drupal.org" that's what they'll see, even though the resulting link will be www.drupal.org. enjoy...

function flexinode_field_url_format($field, $node, $brief = 0) {
  $fieldname = 'flexinode_'. $field->field_id;
  $output = check_plain($node->$fieldname);
  $url = '';
  if (strlen($output) && ! preg_match('%^(\w+://|\w*/)%',$output)) {
    $url = 'http://' . $output;
  } else {
    $url = $output;
  }
  return $output ? '<a href="'. $url .'">'. $output .'</a>' : '';
}