This bug was fixed #93854: Allow autocompletion requests to include slashes for Drupal 7, what about a term beginning with dot (.), say: .NET, this immediately brakes the URL adding the current path's last argument to the autocomplete URL.
Any toughs on that?
Thanks!

See: #93854-223: Allow autocompletion requests to include slashes

As far as I can see, this code:

// See if this string begins with dot
  searchString = searchString.replace(/^\./, '');
  this.searchString = searchString; // This is needs to be done in order to show the matches, otherwise it won't show them

Can be used as well after the line 280 in core/misc/autocomplete.js of Drupal 8.

PD.
Using Drupal 7.14

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Steven Jones’s picture

Status: Needs review » Active
Issue tags: +Needs tests

This will need some simpletests, and an actual patch file for review. See http://drupal.org/contribute/development for a good starting point on the process.

JvE’s picture

Component: javascript » taxonomy.module
Status: Active » Needs review
Issue tags: -Needs tests +Needs backport to D7
FileSize
1.49 KB

Here's a test.
No solution.
Stripping the dot from the search term in the javascript may prevent an error, but still won't allow you to search on terms starting woth a dot.

It may be worth merging this with the already existing #1559142: Allow autocompletion terms to start with a slash even though the cause of the issue is very different. Test coverage and implementation of actual solutions may otherwise interfere between these two issues.

Status: Needs review » Needs work

The last submitted patch, drupal-taxonomy-autocomplete-dot-test-1661098-2.patch, failed testing.

panche’s picture

I see, the main issue then is if in the URL the term can pass with the dot and without breaking the URL.
Some scape char like \ ?
Then in the JS add the \ if the term begins with .
That would require some major changes in the autocomplete callback as well.
Should I try that?

Thanks,
Ricardo.

JvE’s picture

I suspect that it may be the webserver or other config that is disallowing requests for paths or files that start with a dot.
My gut feeling is that we're probably better off if we use some other mechanism for passign the user input to the callback than building a path out of it. A plain querystring comes to mind but this needs more thought.

panche’s picture

I agree, but we can think of an autocomplete enhancement.
I think it should have something like: autocomplete_path?key=QueryString.
And for the sake of backwards compatibility: autocomplete_path/QueryString?key=QueryString.

And of course the new callbacks can use the QueryString on the path like they used to, or the key in the querystring.

Of course, the breaking of the URL still has to be taken into account.

panche’s picture

The team tester found this breaking term: word/.net which also breaks the URL.

I created this two patches for the project running Drupal 7.14.

The revision 35 being the Drupal stable.

What do think about this?

Index: autocomplete.js
===================================================================
--- autocomplete.js	(revisión: 35)
+++ autocomplete.js	(revisión: 73)
@@ -270,6 +270,13 @@
 
   // See if this string needs to be searched for anyway.
   searchString = searchString.replace(/^\s+|\s+$/, '');
+  
+  originalSearchString = searchString;
+  // See if this string begins with dot
+  searchString = searchString.replace(/^\./, '');
+  searchString = searchString.replace('/.', '');
+  db.searchString = searchString;
+  
   if (searchString.length <= 0 ||
     searchString.charAt(searchString.length - 1) == ',') {
     return;
@@ -292,6 +299,7 @@
     $.ajax({
       type: 'GET',
       url: db.uri + '/' + Drupal.encodePath(searchString),
+      data: {search_string: originalSearchString},
       dataType: 'json',
       success: function (matches) {
         if (typeof matches.status == 'undefined' || matches.status != 0) {

And in the taxonomy module:

Index: taxonomy.pages.inc
===================================================================
--- taxonomy.pages.inc	(revisión: 35)
+++ taxonomy.pages.inc	(revisión: 73)
@@ -108,12 +108,19 @@
  * @see taxonomy_field_widget_info()
  */
 function taxonomy_autocomplete($field_name, $tags_typed = '') {
-  // If the request has a '/' in the search text, then the menu system will have
-  // split it into multiple arguments, recover the intended $tags_typed.
-  $args = func_get_args();
-  // Shift off the $field_name argument.
-  array_shift($args);
-  $tags_typed = implode('/', $args);
+  
+  // First look for the search_string via $_GET
+  if(!empty($_GET['search_string'])){
+    $tags_typed = $_GET['search_string'];
+  }else{
+    // If the request has a '/' in the search text, then the menu system will have
+    // split it into multiple arguments, recover the intended $tags_typed.
+    $args = func_get_args();
+    // Shift off the $field_name argument.
+    array_shift($args);
+    $tags_typed = implode('/', $args);
+  }
+  
 
   // Make sure the field exists and is a taxonomy field.
   if (!($field = field_info_field($field_name)) || $field['type'] !== 'taxonomy_term_reference') {
panche’s picture

Attaching a patch, see if it's good enough.

nod_’s picture

Status: Needs work » Needs review
droplet’s picture

+++ b/core/modules/taxonomy/taxonomy.pages.incundefined
@@ -108,13 +108,18 @@ function taxonomy_term_feed(Term $term) {
+  if(filter_input(INPUT_GET, 'search_string')){
+    $tags_typed = filter_input(INPUT_GET, 'search_string');

it should use symfony2's request()

It also worth to check why Drupal does not handle leading DOT in path.

JvE’s picture

Drupal (apache) rejects paths starting with a dot due to this snippet from the .htaccess file in the drupal root:

# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$">
  Order allow,deny
</FilesMatch>
droplet’s picture

Priority: Minor » Normal
Status: Needs review » Needs work
panche’s picture

If that gets fixed, the patch here only would be a change in the behavior of the autocomplete, adding a search_string as a parameter, then modules like taxonomy catch the search string as a parameter.

And yes! it should be the symfony2's request(). But didn't know about the Request until @droplet pointed out.

Sorry, don't know Symfony that much. Time to learn new stuff!!

mahipal46’s picture

#8 is work for me thanks

mahipal46’s picture

Status: Needs work » Needs review
Issue tags: -Needs backport to D7

Status: Needs review » Needs work

The last submitted patch, drupal-taxonomy-autocomplete-dot-1661098-8.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

PHP code was stripping the \ in the code

klonos’s picture

Issue summary: View changes

..converted links to issues to their [#xxxxxx] equivalents so they can also indicate issue title and reflect issue status.

droplet’s picture

Version: 8.x-dev » 7.x-dev
Issue summary: View changes

D8 is using jQuery UI Autocomplete now

dcam’s picture

Status: Needs work » Closed (duplicate)