I'm not sure if this is a problem in autocomplete.js itself or elsewhere, but filing it here since the front-end is where this bug is surfacing: if auto-complete is asked to search on a partial string containing a slash ('/'), the web server returns a 404 response, resulting in the ugly JavaScript error pop-up.

Easiest way to reproduce: create a node and type '/' in the 'authored by' field. Not restricted to this field or form though, same happens for example when using the taxonomy field's auto-complete widget.

In case this is web server-specific: Ubuntu, PHP 5.3, Apache/2.2.14

CommentFileSizeAuthor
#15 slashes.patch664 bytesmichaelfavia
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mr.baileys’s picture

Complete error message:

An AJAX HTTP error occurred.
HTTP Result Code: 404
Debugging information follows.
Path: http://d7.patch.localhost/user/autocomplete
StatusText: Not Found
ResponseText: 
404 Not Found
Not Found
The requested URL /user/autocomplete// was not found on this server.
Apache/2.2.14 (Ubuntu) Server at d7.patch.localhost Port 80

Note that firebug shows that the request itself is correctly encoded:

http://d7.patch.localhost/user/autocomplete/%2F

... and the 404 is Apache's 404 page, not Drupal's:

<h1>Not Found</h1>
<p>The requested URL /user/autocomplete// was not found on this server.</p>
<hr>
<address>Apache/2.2.14 (Ubuntu) Server at d7.patch.localhost Port 80</address>
droplet’s picture

+1
only happen when CLEAN URL enabled

rfay’s picture

I think this may be innate to the whole approach here with autocomplete. I wonder if there's a way to make Apache ignore extra slashes (but I don't think there will be a way to get it to search on those slashes).

Of course the reason it's not a problem without clean URLs is that then the extra slash is part of the query string, not part of the base url.

This is exactly the same in D6, is it not?

mr.baileys’s picture

This is exactly the same in D6, is it not?

Oddly enough, no (at least not at first glance). Did a quick test on the user auto-complete field, and D6 seems to take the slashes just fine, so it seems this problem is new to D7...

Ideally, the argument to the auto-complete path would always be passed as a query parameter rather than a path element (you're accessing the same resource anyway, so it would make more sense too I guess)

So
http://example.com/user/autocomplete?ac=partial_string
instead of
http://example.com/user/autocomplete/partial_string

That would fix this issue. This probably is considered an API change though.

rfay’s picture

I don't think I'd consider that an API change. Seems like something we should do. I'd say roll a patch.

mr.baileys’s picture

joachim’s picture

> Ideally, the argument to the auto-complete path would always be passed as a query parameter rather than a path element (you're accessing the same resource anyway, so it would make more sense too I guess)

Do we really need to make that change? As stated above, this works fine on D6 passed in as a path. How does D6 do it?

anrikun’s picture

Subscribing.

stBorchert’s picture

Drupal 6 uses Drupal.encodeURIComponent to encode the given string.
Drupal 7 uses encodeURIComponent which doesn't convert %2F back to /.

If you modify autocomplete.js line 294 (url: db.uri + '/' + encodeURIComponent(searchString),) to url: db.uri + '/' + Drupal.encodePath(searchString), slashes aren't a problem anymore.

edit: this has been committed with #284899: Drupal url problem with clean urls

joachim’s picture

So is this bug effectively fixed by #284899: Drupal url problem with clean urls?

stBorchert’s picture

No, unfortunately #284899: Drupal url problem with clean urls created this bug by fixing another :/

vitok-dupe’s picture

subscribe

michaelfavia’s picture

affected via linkit. subscribe.

benanderson’s picture

subscribing

michaelfavia’s picture

Status: Active » Needs review
FileSize
664 bytes

I just added forward slashes to the regex that removes trailing and leading whitespace. Along with some comments for those who don't like reading regex ors.

I don't know if we want to include forward slashes in the ajax searches but if we do we'll have to go another route. This scratched my itch and fixes the issue with linkit module and "http://" links.

pillarsdotnet’s picture

joachim’s picture

Status: Needs review » Needs work

> I don't know if we want to include forward slashes in the ajax searches

Yes, I would say we do. The ajax search should work for whatever the user types, since there is no restriction on characters in term names.

mr.baileys’s picture

Status: Needs work » Closed (duplicate)

Apologies for closing this issue, but it looks like this is a duplicate of #93854: Allow autocompletion requests to include slashes which has more background and history, so I think it's beneficial to continue the discussion there...