The link to the selected suggestion is not a valid URL on my Drupal project. The link used is something like http://example.com375 (no slashed after domain name!), resulting in a 404 when selected or clicked.

In the demo View that comes with search_autocomplete, called "nodes_autocomplete" I have the exact same problem.

The preview output of the "nodes_autocomplete"-View will look like this:

[
  {
    "link" : "http://example.com375",
    "value" : "Profil DP 120",
    "fields" : {
      "title" : "Profil DP 120",
      "name" : "author: Jane Doe"
    },
    "group" : {
      "group_id" : "product",
      "group_name" : "product"
    }
  },

Thank you very much for your help!

CommentFileSizeAuthor
#8 url-trimmed--2477199-8.patch2.76 KBdom.

Comments

propercroc’s picture

Title: Link URL is not the nodes URL, but something shortened » Link URL is not the nodes URL, but something shortened that leads to 404
dom.’s picture

Hi !
Links have to be a URL ! So in views, the field you choose for the "link setting" MUST BE a string representing a URL. It you put the NID as a link it won't work. Try using "Content: Link" field for instance. If you can't, you will have to "Rewrite the output of this field" in the view to make the output being a link.

spanac’s picture

Confirming this problem on clean install. Found a problem in new version of search_autocomplete/views/theme/views_search_autocomplete_style.theme.inc regarding URL extracting. Patch 7.x-4.5 from 2015-04-23 or use an older version of this great module (version 7.x-4.3+2-dev from 2015-03-24 is working without this problem).

--- search_autocomplete/views/theme/views_search_autocomplete_style.theme.inc
+++ search_autocomplete/views/theme/views_search_autocomplete_style.theme.inc
@@ -52,8 +52,8 @@
 
     // Extract the URL...
     $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
-    $link_value = $row[$style_options['input_link']]->raw;
-    if (preg_match("/$regexp/siU", htmlspecialchars_decode($row[$style_options['input_link']]->raw, ENT_QUOTES), $matches)) {
+    $link_value = $row[$style_options['input_link']]->content;
+    if (preg_match("/$regexp/siU", htmlspecialchars_decode($row[$style_options['input_link']]->content, ENT_QUOTES), $matches)) {
         $link_value = $matches[2];
     }
     if (url_is_external($link_value) || valid_url($link_value, TRUE)) {
@@ -68,7 +68,7 @@
     /* ----------------
      * Build the value...
      * ----------------  */
-    $object['value'] = trim($row[$style_options['input_label']]->raw);
+    $object['value'] = trim(strip_tags($row[$style_options['input_label']]->content));
 
     /* ----------------
      * Build the array of output fields...
@@ -76,8 +76,8 @@
     $object['fields'] = array();
     foreach ($style_options['output_fields'] as $field_name) {
       // Add the field if the value is not null.
-      if (array_key_exists($field_name, $row) && $row[$field_name] && $row[$field_name]->raw) {
-        $object['fields'][$field_name] = trim($row[$field_name]->label . ' ' . $row[$field_name]->raw);
+      if (array_key_exists($field_name, $row) && $row[$field_name] && $row[$field_name]->content) {
+        $object['fields'][$field_name] = trim($row[$field_name]->label . ' ' . $row[$field_name]->content);
       }
     }
 
@@ -86,7 +86,7 @@
      * ----------------  */
     if ($style_options['group_by']) {
       $group_type = $style_options['group_by'];
-      $group_name = $row[$group_type]->raw;
+      $group_name = $row[$group_type]->content;
       if (!isset($objects[$group_name])) {
         $objects[$group_name] = array();
       }
spanac’s picture

Priority: Major » Critical
caspianroach’s picture

I can confirm that this does happen on a clean installation, just found out about this module, wasn't sure why it wasn't working. I think the /.../ part in the url is being mistaken for an regexp pattern and ends up ignored.

darkdante’s picture

Hi.

I can confirm this problem too, after reverting back to 7.x-4.4 it worked properly again.

Kind Regards

cozzamara’s picture

The same for me...

dom.’s picture

Status: Active » Needs review
StatusFileSize
new2.76 KB

Hi all !
Here is a patch that should solve the issue. Can one of you have a try and review it please ?
Thanks

cozzamara’s picture

The seems to work for me.

cozzamara’s picture

The patch sorry....

dom.’s picture

@cozzamara: thanks !
Anyone else can double confirm so I can create another release using this ?

vivand’s picture

reverted back to April 20 DEV version which works ok.

dom.’s picture

@vivand : what about this patch ?

renat’s picture

Status: Needs review » Reviewed & tested by the community

Patch from #8 works like a charm for me, so, based on previous confirmation of it's validity and keeping in mind that it was proposed by a module's maintainer, marking this issue as RTBC.

migmedia’s picture

@dom.
patch restores the original behavior. It fixes this issue for me.
Thanks

theodorosploumis’s picture

Patch from #8 did not work for me with 7.x-4.5. I 've installed 7.x-4.x-dev (2015-Apr-20) to fix it.

Notice that I have override the initial Views used for the autocomplete.

  • 0055587 committed on 7.x-4.x
    Issue #2477199 by Dom.: Link URL is not the nodes URL, but something...
dom.’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Hi,
Sorry for delay, I was off for a few days. Patch is commited and available with the 7.x-4.x It will be included in the 7.x-4.6 release.