I have several link urls entered where the last portion is getting truncated, one such example is:

.../cm/community/features/interviews/blog/recession-exacerbates-data-management-issues-but-could-make-investigations-a-nightmare/?cs=32640

When output in a View as plain text it's truncated to:

.../cm/community/features/interviews/blog/recession-exacerbates-data-management-issues-but-could-make-investigations-a-nightmare/

which results in a 404 page...

This is happening for several urls of different lengths, they all get truncated right before the '?'. I'm assuming that the url isn't passing the RegEx test for valid urls because the question mark appears right after a forward slash...

I stink at RegEx, so I can't provide a possible solution, but I imagine it's something similar to http://drupal.org/node/401138

-Chris

Comments

hubkei’s picture

Version: 6.x-2.5 » 6.x-2.6

subscribing.
same problem here on vers. 6.x-2.6 of the Link field. The ? symbol after a / forward slash make the the url to be cut off right before.

nally’s picture

I am experiencing a case where "? and what follows" (i.e. a query string) is truncated, even though there is no / just before the ?.

Is anyone else experiencing that? Would that be the same bug as this one?

UPDATED: False alarm. I was theming using
$node->field_link_to_source['0']['url']
instead of
$node->field_link_to_source['0']['display_url']

cgjohnson’s picture

This is also happening to me - when I output a Link field value as a Views field (and need to use the plain text display in Views), it breaks. Any solution? thanks.

funana’s picture

Priority: Normal » Critical

Confirm: Links get truncated before ? in URL.

Changed title and priority of the Issue Report.

funana’s picture

Title: A question mark after forward slash in url causes truncation of url » A question mark in url causes truncation of url
marcushenningsen’s picture

Subscribing

funana’s picture

Does anybody have an idea how to solve that? The module is useless for me with that bug...

Tried to hack the code like it is done in http://drupal.org/node/401138 but it doesnt work.

Help very appreciated!

sijuwi’s picture

Subscribing

sijuwi’s picture

Problem is around line 326 in link.module - I removed line 326 - 330. Though it works I have no idea what side effects will result nor why it was put there in the first place.

funana’s picture

Thank you very much, sijuwi. Works!

jcfiala’s picture

Status: Active » Closed (works as designed)

This is intentional.

When a url is sanitized, the querystring (the chunk after the ?) is kept in a different variable than the url is. So, for http://www.example.com/index.html?query=here, the 'url' field holds 'http://www.example.com/index.html', and the 'query' field holds 'query=here'.

Among other things, this lets us process the url with the url() function, thus making sure we've got a nice valid url that's been processed. If you need a full url, use the 'display_url' as in comment #2, above.

funana’s picture

ahhh, now I see. Thank you!

skyzlmt’s picture

display_url truncates long links with "..." !!!!

skyzlmt’s picture

My solution...

Since the display_url (for me) was also truncating... I came up with the following PHP code. I am not a PHP guy (Microsoft .Net) but its simple conditional statement that I followed, so my apologies if this is ugly!

I am using CCK link. I left the H3 tag in for clarity of where this starts and ends.

Simply, it handles the URL and Query separately.
Print the URL to screen
check to see if there is a value in [query]
If YES: print question mark and query value.
exit condition
Print remainder of URL.

(of course now someone will say "you are using CCK Links? Oh, just use this _____ property!" hah)

 <h3 >    
<a href="<?php print $field_article_link[0][url]; 
	if ($field_article_link[0][query] != ""):  
	  print "?"; print $field_article_link[0][query];
	endif; ?> 
	" target="<?php print $field_article_link[0][attributes][target]; ?>"><?php print $title; ?></a> 
 </h3>
heatherann’s picture

skyzlmt, that is a beautiful thing. Those truncated URLs were driving me crazy, and this has fixed it even for the really long ones.

My code is in my template.php:

function MYTHEME_resource_order_link($resource) {

    if ($resource->field_order_link[0][url]) {
    //because I only run this if there is a link

        $link_url = $resource->field_order_link[0][url];
        //start with the base url

        if ($resource->field_order_link[0][query]) {
        //check if there is a query string

            $link_url.= '?'.$resource->field_order_link[0][query];
            //if there is, then add '?' and the query string to the end of the url

        }
            return '<a href="'.$link_url.'" class="link">'.t('Order free print copy').'</a>';
    }
}

Then I just say MYTHEME_resource_order_link($node); in my tpl.php files, wherever I need it.

bryangullan’s picture

Title: A question mark in url causes truncation of url » Node edit form does not display full URL (display_url) in the form field for the UR, resulting in loss of query string on saving
Status: Closed (works as designed) » Active

I understand the reasoning for having a truncated version of the URL stored, but as things stand you can't edit content without losing the query string. I've modified the title of this to reflect the defect.

To replicate:
* Add a URL with a query string into the URL field
* Save the node
* URL on 'view' of page is correct, and includes the query string.
* Now edit the node. See the trimmed URL in the URL field.
* Save the node
* View the page - URL is stripped down, since that's what was in the URL field on saving.

The form field should use the full, unmodified original URL, so that subsequent saves retain what was originally entered. I don't think there's some setting I've overlooked, and I've tried this with the Garland theme to rule out an impact from my custom theme.

bryangullan’s picture

Version: 6.x-2.6 » 6.x-2.9

(Forgot to update the version)

dqd’s picture

Category: bug » feature
Priority: Critical » Normal

as jcfiala mentioned above: it generally works as designed. any individual modifikations and patches for certain use case are welcome to provide here for others, but please without changing issue status.

thx 4 understanding

dqd’s picture

Status: Active » Closed (works as designed)
ferahl’s picture

Thanks for this, this is how I do it in D7:

$url = $item['url'];

if (sizeof($item['query']) > 0) {
	$url .= '?';
	foreach ($item['query'] as $key => $value) {
	  $url .= $key . '=' . $value;
	  if ($value !== end($item['query'])) $url .= '&';
	}
}