Hi,

I like the breadcrumb trail feature based on active facets. Problem is the URL encoding can lead to broken links. For example, I have an entity with a field called "Category" and is a taxonomy term reference. Indexing this field with Search API gives facet links like:

/search?f[0]=category%3Aname:Apple

The facet is actually category:name, but must be written with a filter in the URL like: category%3Aname:Apple

The breadcrumb code in url_processor_standard.inc does not take this into account. It gives URLs like:

/search?f[0]=category%3Aname%3AApple

...which breaks the filter (it does nothing). So the difficult step comes down to this line 87 in setBreadcrumb()_

$query[$this->filterKey][] = $item['field alias'] . ':' . $item['value'];

In my case the field alias is 'category:name' which ends up correctly as 'category%3Aname', but the ':' is incorrectly jumbled up as well in the l() function, so the link does not work.

CommentFileSizeAuthor
#10 rawurlencode_rangefield-1344076-5.patch924 bytesemorency
#3 1352082-3.patch737 bytesAnonymous (not verified)

Comments

Anonymous’s picture

Maybe one solution is to rewrite facet links to:

category[name]:Apple instead of category%3Aname:Apple

?

Anonymous’s picture

Status: Active » Needs work

Ha, the solution is easier than I thought:

$query[$this->filterKey][] = urlencode($item['field alias']) . ':' . $item['value'];

Just urlencode() the field alias and it works!

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new737 bytes

Patch attached.

mrfelton’s picture

Does the job for me. Thanks!

cpliakas’s picture

Status: Needs review » Needs work

The theory of this makes sense, and I definitely want to test it out. Marking as "needs work" because I think we should be using drupal_encode_path() instead of urlencode.

Thanks for the contribution,
Chris

cpliakas’s picture

Issue tags: +low hanging fruit

Putting on the low hanging fruit list.

Anonymous’s picture

Component: Code (functionality) » Code

So we should use rawurlencode() instead of urlencode()?
http://stackoverflow.com/questions/996139/php-urlencode-vs-rawurlencode

cpliakas’s picture

It's Drupal best practices to use rawurlencode() in favor or urlencode(), so that is the direction we should go. The drupal_encode_path() function uses rawurlencode() but doesn't encode forward slashes for aesthetic reasons. The more I think about it the forward slashes would need to be encoded in the off chance that the facet name contains them. If we switch to rawurlencode() then this patch is RTBC.

Thanks,
Chris

cpliakas’s picture

Title: URL encoding and breadcrumbs links » Broken facet URLs in breadcrumb links when facet alias contains punctuation
Component: Code » User interface
Status: Needs work » Fixed

Committed at http://drupalcode.org/project/facetapi.git/commit/610fc7f with urlencode() switched to rawurlencode().

Congrats on becoming the 18th committer to Facet API!

emorency’s picture

StatusFileSize
new924 bytes

Sorry, wrong issue see http://drupal.org/node/1344076

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