Issue: The following errors are returned when Apache Solr Search Integration is used while Securepages is enabled:

* warning: parse_url(/folder/search/apachesolr_search/burton?filters=tid:232) [function.parse-url]: Unable to parse URL in /var/www/html/folder/sites/all/modules/securepages/securepages.module on line 152.
    * warning: extract() [function.extract]: First argument should be an array in /var/www/html/folder/sites/all/modules/securepages/securepages.module on line 152.

How to reproduce:

Enable Apache Solr Search Integration & Securepages
Enable facets and facet blocks
Search for a keyword which will return facet blocks
Click on a facet
The result set that is returned will produce the error. This only seems to happen when I apply one facet. Having multiple facets applied to the result set does not produce the error.

Code that throws the error (from Securepages.module):

extract(parse_url($form['#action']));

That is line 52 from a form_alter hook.

I believe the colon before the term_id in the form action is throwing off parse_url().

Comments

pwolanin’s picture

Hmm, perhaps we need to urlencode the facet links

mkalkbrenner’s picture

subscribe

Anonymous’s picture

Agreed, but I couldn't get facets to apply after urlencoding them. Probably missing something small.

EDIT: what I had posted won't work

mkalkbrenner’s picture

Status: Active » Needs review
StatusFileSize
new569 bytes

@gregor7777:

I don't have a ssl setup up and running right now. So could you please test this patch for url encoding?

Anonymous’s picture

Sure thing, I'll take a look today. thanks

Anonymous’s picture

Tested patch, not seeing any difference in behavior.

After applying patch:

http://mysite.com/myfolder/search/apachesolr_search/686?filters=tid:315

...which is a taxonomy facet applied produces:

 * warning: parse_url(/myfolder/search/apachesolr_search/686?filters=tid:315) [function.parse-url]: Unable to parse URL in /var/www/html/myfolder/sites/all/modules/securepages/securepages.module on line 152.
* warning: extract() [function.extract]: First argument should be an array in /var/www/html/myfolder/sites/all/modules/securepages/securepages.module on line 152.

http://mysite.com/myfolder/search/apachesolr_search/686?filters=tid:315+...

...which is clicking on a second taxonomy facet (keeping the taxonomy facet from the first example applied) produces no warning.

http://mysite.com/myfolder/search/apachesolr_search/686?filters=sm_cck_f...

...which is a CCK field set as a facet produces no warning.

http://mysite.com/myfolder/search/apachesolr_search/686?filters=sm_cck_f...

..which is the same CCK field from above and a taxonomy facet applied produces no warning.

So, to round that up, the only time an warning is produced is the when I apply a taxonomy facet first. Applying a second taxomomy facet, or any combination of applying a CCK field facet does not produce the warning.

This behavior is the same regardless of whether or not the patch was applied.

Anonymous’s picture

Status: Needs review » Needs work

forgot to set the status

mkalkbrenner’s picture

Version: 6.x-1.0-beta5 » 6.x-1.x-dev
Assigned: Unassigned » mkalkbrenner
Status: Needs work » Needs review
StatusFileSize
new990 bytes

@gregor7777

I made a mistake when using array_walk to encode the filters.
I attached a corrected version of my patch which works for me. Please test again.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

Very nice.

Tested and can confirm that the patch eliminates the warnings, is replacing the offending character in the URL, and appears to have no negative side effects.

Ugly URLs though. :)

http://mysite.com/myfolder/search/apachesolr_search/ski?filters=sort_pri...

pwolanin’s picture

Why do we need the urldecode? It seems like will decode when adding to $_GET?

mkalkbrenner’s picture

StatusFileSize
new623 bytes

@pwolanin:

You're right. I adjusted the patch and removed the additional urldecode.

While playing around with securepages module (which really has some open issues from my point of view) I created a setup where the query string got urlencoded twice.

JacobSingh’s picture

Status: Reviewed & tested by the community » Fixed

I didn't test this with securepages because I don't have SSL setup, and don't feel like dealing with it, but it seems to have no effect on normal operation.

Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mkalkbrenner’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new762 bytes

Same strategy for building querystrings as introduced with patch from comment #11 must be applied to breadcrumbs, too.
Because patch from comment #11 is already released, here's an additional one for breadcrumbs.

pwolanin’s picture

Looks reasonable

pwolanin’s picture

Status: Needs review » Needs work

the committed patch uses drupal_urlencode() while this patch uses rawurlencode()

So, one (or both) of those must be wrong.

In fact, since this is for the query string (not path) that suggests we shoudl possibly be using: str_replace('%2F', '/', rawurlencode($text))

per the non-clean URL code in http://api.drupal.org/api/function/drupal_urlencode/6

pwolanin’s picture

per #310139: drupal_query_string_encode() should not call drupal_urlencode() and Damien, we shoudl just use rawurlencode(), which means the previously changed code needs to be similarly altered.

In fact, maybe we shoudl just do this?

$querystring = 'filters='. rawurlencode(implode(' ', $fq));
pwolanin’s picture

Wiat, now I'm at a loss as to why this is required. We are always passing our query string through url() which means that drupal_query_string_encode() is applied to all of them. What am I missing - it would seem like these changes give us double-encoding.

mkalkbrenner’s picture

The patch from #11 used drupal_urlencode and was committed to CVS. Later drupal_urlencode seems to be replaced by rawurlencode in CVS. That's why the patch from #14 now uses rawurlencode, too.

@ #17 pwolanin:
replacing implode(' ', $fq) by implode('+', $fq) was one thing needed to solve the incompatibility to secure_pages module.

@ #18 pwolanin:
in our cases $options['query'] always seems to be an already prepared querystring and not an array, so drupal_query_string_encode() will not be called from url():

function url($path = NULL, $options = array()) {
  ...
  if (is_array($options['query'])) {
    $options['query'] = drupal_query_string_encode($options['query']);
  }

So far I can't see any double quoting here in my setup with patch #14 applied.

mkalkbrenner’s picture

Status: Needs work » Needs review
pwolanin’s picture

StatusFileSize
new1.48 KB

Ah, right - I see why it doesn't get encoded.

Try this patch, since ideally we would not use +

mkalkbrenner’s picture

I remember that secure_pages chunks an url and than uses html_build_query() to reconstruct it internally.

print http_build_query(array('filters' => 'tid:315 tid:316'));

Output:

filters=tid%3A315+tid%3A316
pwolanin’s picture

can you check if the above patch works?

JacobSingh’s picture

I'm having trouble testing this because when I enable SSL on my MAMP install. It:

1). Goes slow as hell
2). Fails to make outgoing HTTP requests.

I don't feel like dealing with finding out why, but the patch above doesn't seem to cause any problems when not using secure pages.

pwolanin’s picture

Status: Needs review » Fixed

committed to 6.x CVS, follow up if it causes issues.

mkalkbrenner’s picture

Status: Fixed » Needs review

Sorry that I reopen this issue.

After reading through some specifications at w3c I'm of the opinion that spaces are not allowed in URLs and must be escaped.

"Spaces and control characters in URLs must be escaped for transmission in HTTP, as must other disallowed characters."
http://www.w3.org/Addressing/URL/url-spec.txt

According to the newer document http://labs.apache.org/webarch/uri/rfc/rfc3986.html in seciton "C. Delimiting a URI in Context" whitespaces delimit an url or must be ignored if they occur within "" or <>. Both treatments of whitespaces will break apachesolr urls.

From my point of view spaces must be escaped as '+'. And in addition to this issue about querystrings, spaces should also be avoided in search key words.

Was there a discussion about spaces in apachesolr urls earlier?

pwolanin’s picture

With this patch spaces ARE escaped as '%20', which is the standard for URLs, rather than as '+'.

mkalkbrenner’s picture

If I look at your code you must be right. So it seems I made a mistake when applying your patch because I still saw spaces in breadcrumb in our test environment. Please excuse ...

As I wrote the first patch I decided to be compatible to urls created by securepages which used html_build_query(). Unfortunately I'm unable to check if %20 works until Monday.

What do you think about spaces between search key words? Shouldn't these be encoded as well?

pwolanin’s picture

The spaces between search keywords will by urlencoded by the Drupal url() function, so I think that's not an issue.

Seems most browsers display %20 decoded, so it may not be obvious when a link actually contains it.

pwolanin’s picture

Status: Needs review » Fixed

let me know if this is not fixed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.