While working on a client's site I noticed links with a ? are being converted to &. For example if we post youtube link:
http://www.youtube.com/watch?v=FyiBOcaUq6g once rendered it will look like http://www.youtube.com/watch&v=FyiBOcaUq6g.

After a lot of debugging I located the issue on lines 430-435 in link.module.

// Separate out the query string if any.
if (strpos($url, '?') !== FALSE) {
$query = substr($url, strpos($url, '?') + 1);
parse_str($query, $query_array);
$item['query'] = $query_array;
$url = substr($url, 0, strpos($url, '?'));
}

Removing this lines of code resolved my issue.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chaunceyt’s picture

rreiss’s picture

Issue summary: View changes

@chaunceyt Your patch fixed another issue for me. (Duplicate query params.)
See https://www.drupal.org/node/1646360 for similar issue.

Thanks!

jcfiala’s picture

Status: Active » Needs review

Remember folks - if you post a patch to fix a problem, set the status of the issue to "Needs Review".

If you've tested a patch and agree that it fixes the problem, then set the status of the issue to "Reviewed & Tested by the Community."

Status: Needs review » Needs work
jcfiala’s picture

Status: Needs work » Postponed (maintainer needs more info)

Hey @chaunceyt, can you give me more information about how this field is setup and being displayed? I've got an automated test that checks that a link with a querystring shows up normally.

If you could give me more information about the specifics of this field - how it's configured - and how it's displayed, that would help.

(I notice this ticket is two years old, so I realize you may not reply.)

jeffwpetersen’s picture

I have a similar issue with proxy sites.

http://proxy.kclibrary.org/login?url=http://infotrac.galegroup.com/itweb...
is displayed as
http://proxy.kclibrary.org/login?url=http%3A//infotrac.galegroup.com/itw...

// Separate out the query string, if any.
if (strpos($url, '?=this-alters-my-output') !== FALSE) {
    $query = substr($url, strpos($url, '?') + 1);
    $url_parts['query'] = _link_parse_str($query);
    $url = substr($url, 0, strpos($url, '?'));
  }
  $url_parts['url'] = $url;
  return $url_parts;
}
jcfiala’s picture

@jeffwpeterson - So, the url in question has two ? in it? Well, then it should be doing this - per the internet standard, any ? in a url that isn't indicating that there's a querystring should be encoded. Does the url with the encoded second ? work properly?

(Of course, a lot of websites don't pay attention to the standards.)

jeffwpetersen’s picture

(entered url) http://proxy.kclibrary.org/login?url=http://infotrac.galegroup.com/itweb...

(result url) http://proxy.kclibrary.org/login?url=http%3A//infotrac.galegroup.com/itw...

http://beta.kclibrary.org/research-resources/research-databases/chiltonl...

In the result url the second ":" is converted to "%3A" after the "?" of the query string. There are not 2 "?";

The entered url works properly from inside the library. The result url throws an error.
This is a proxy filter that allows only url's initiated from inside our system to access that database. It is a standard in libraries as far as I know.

J.

buhuhus’s picture

electroponix’s picture

I also have this issue. Proxy for a library. I have to http://'s in the URL. The second one gets encoded and won't pass through the proxy. Has anyone come up with a fix for this?

KoshaK’s picture

I have the problem where ( ) converted to %28 %29 im using 7.x-1.3
Update: ( ) converted only when the " ? " used. by removing " ? " for test purposes the ( ) are in place.

for example the link: http://www.website.com/click?p(123)a(123456)g(123456789)
converts to: http://www.website.com/click?p%28123%29a%28123456%29g%28123456789%29

Summit’s picture

Hi,
Tradedoubler urls are also not validated, see also https://www.drupal.org/node/2407553
Is with this patch this validated?
Greetings, Martijn

jeffwpetersen’s picture

I have tracked down the bug and think I can explain it more clearly now.

I have a url with a nested query string. The query string is a url itself.
"http://proxy.kclibrary.org/login?url=http://search.proquest.com/abicompl..."

The drupal url() function in the code below (line 518) is altering $url_parts['query'] incorrectly.

http://api.drupal.org/api/drupal/includes%21common.inc/function/url/7
'query': An array of query key/value-pairs (without any URL-encoding) to append to the URL.

  if (!empty($url_parts['url'])) {
    $item['url'] = url($url_parts['url'],
      array('query' => isset($url_parts['query']) ? $url_parts['query'] : NULL,
      'fragment' => isset($url_parts['fragment']) ? $url_parts['fragment'] : NULL,
      'absolute' => !empty($instance['settings']['absolute_url']),
      'html' => TRUE,
      )
    );
  }
So: http://proxy.kclibrary.org/login?http://search.proquest.com/abicomplete?accountid=37396
Becomes:http://proxy.kclibrary.org/login?url=http%3A//search.proquest.com/abicomplete%3Faccountid%3D37396 

This is not an issue in Drupal8. YAY!

jeffwpetersen’s picture

Status: Postponed (maintainer needs more info) » Active
dgtlmoon’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
dgtlmoon’s picture

jeffwpetersen’s picture

The patch does not address this issue.

The query string is being separated out and feed into the url(); function. The url(); function is the problem. See my comment #13 for details.

k.cook’s picture

Also having trouble with proxy links. I see that the links on this page are working properly. Is there another fix available that has corrected the trouble with replacing question mark in the queried link?

https://www.kclibrary.org/topics/newspapers
http://proxy.kclibrary.org/login?url=http://search.proquest.com/chicagot...
http://proxy.kclibrary.org/login?url=http://www.bizjournals.com/kansasci...
http://proxy.kclibrary.org/login?url=http://search.proquest.com/newsstan...

k.cook’s picture

Hi. I am trying to solve same issue for using EZProxy URLs. I see that the URLs being used at www.kclibrary.org are now working despite this issue. Jeff - Can you share how this was corrected?

lperepol’s picture

lperepol’s picture

For EZproxy this may help. "EZProxy: Use qurl, not url, really"
https://bibwild.wordpress.com/2013/01/08/ezproxy-use-qurl-not-url-really/

ismailM’s picture

I'm having the same issue with Drupal 8.5.5^

Is there a solution to fix this? Thanks!

jeffwpetersen’s picture

Comment out part of this function to make proxy work.

function _link_parse_url($url) {
  $url_parts = array();
  // Separate out the anchor, if any.
  if (strpos($url, '#') !== FALSE) {
    $url_parts['fragment'] = substr($url, strpos($url, '#') + 1);
    $url = substr($url, 0, strpos($url, '#'));
  }
  /*
  // Separate out the query string, if any.
  if (strpos($url, '?') !== FALSE) {
    $query = substr($url, strpos($url, '?') + 1);
    $url_parts['query'] = _link_parse_str($query);
    $url = substr($url, 0, strpos($url, '?'));
  } */
  $url_parts['url'] = $url;
  return $url_parts;
}