Project:Flexinode
Version:4.6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

- 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

#1

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

#2

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.

#3

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.

#4

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).

<?php
// 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>' : '';
}
?>

#5

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

AttachmentSize
field_url_2.patch 1.07 KB

#6

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.

AttachmentSize
field_url_3.patch 615 bytes

#7

*** 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/"):

  • 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 ? '<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.

AttachmentSize
field_url_4.patch 615 bytes

#8

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 ?

#9

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

#10

Version:<none>» 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.

#11

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

#12

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>' : '';
}
AttachmentSize
url-4_6_0.patch 915 bytes