Typing 'watch' in TaxiSelect field output [object object].

Steps to reproduce this issue.
1. Install TaxiSelect 2.0-apha 1 or previous version
2. Configure and connect with any vocabulary.
3. Add the term watches in your vocabulary.
4. Type in watch. Wait. [object object] will be output as a result. And nothing else. Expected result is to output results if any not [object object].
5. Type in wat, watc, watches doesn't return the error. Only watch does.

This issue was present in previous version of TaxiSelect. But it is just now that I made the connection with the word 'watch'.

Using
-TaxiSelect 2.0-apha 1
-Drupal 6.14
-Garland theme
-Firefox 3
-Site OS: Ubuntu Server 8.04 LTS
-End user OS: Ubuntu Desktop 8.04 LTS

Let me know if you need more information.

Files: 
CommentFileSizeAuthor
#18 590148-18-autocomplete-cache-namespace.patch1.03 KBAlan D.
PASSED: [[SimpleTest]]: [MySQL] 26,583 pass(es).
[ View ]
#14 screenshot.png41.95 KBFrancewhoa
#10 autocomplete-cache-namespace.patch1.05 KBAlan D.
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in autocomplete-cache-namespace_0.patch.
[ View ]
#8 1-creating-field.png15.93 KBFrancewhoa
#8 2-vocabulary.png14.21 KBFrancewhoa
#8 3-autocomplete-works.png13.41 KBFrancewhoa
#8 3-autocomplete-works-ie-7.png52.87 KBFrancewhoa
#8 3-autocomplete-works-safari.png26.62 KBFrancewhoa
#8 3-autocomplete-works-opera.png33.81 KBFrancewhoa
#4 autocomplete-cache-namespace.patch1.09 KBAlan D.
Failed: Failed to apply patch.
[ View ]
#7 autocomplete-cache-namespace-590148-7.patch1.06 KBAlan D.
Passed: 14717 passes, 0 fails, 0 exceptions
[ View ]
#6 drupal-watch-auto-complete.gif14.96 KBAlan D.

Comments

Alan D.’s picture

lol. Turn off Firebug!

Francewhoa’s picture

Laugh. That would be easy to fix. Thanks Alan. I'll try that then post result here.

Francewhoa’s picture

Nope didn't work. It isn't Firebug. I turn it off but same error is output.

To confirm this I did more testing with two other browsers.
-SeaMonkey 1.1.17
-Galeon 2.04

Those 2 browsers don't even have Firebug plug-in install. But they output the same error. The output is actually [object Object] not [object object]. Notice the capitalized 'O'. I did a typo in my first comment.

Same result using Windows XP and Ubuntu 8.04 LTS.

All Devel modules are deactivated.

Alan D.’s picture

Title:Autocomplete.js errors with Mozilla based browsers, due to a namespace conflicts between search terms and object properties» Typing 'watch' triggers an error
Version:7.x-dev» 6.14
StatusFileSize
new1.09 KB
Failed: Failed to apply patch.
[ View ]

This is a namespace clash with Mozilla browsers within the core Drupal autocomplete.js

Browsers:
FireFox 3.5
SeaMonkey 1.1.17
Galeon 2.04

So far the following name cause logical error during the auto-complete process:

no autocomplete AJAX, no drop-down
constructor

no autocomplete AJAX and [object Object] is shown in the dropdown and prototype is returned when selected

# Some methods inherited from Function.prototype
toSource
toString
valueOf

# All methods / properties inherited from Object.prototype
propertyIsEnumerable
hasOwnProperty
watch
unwatch
__defineGetter__
etc

Some keywords appear to pass, like some methods / properties inherited from Function.prototype: apply, call, name, caller, length, ...

The easiest workaround is to add a prefix to the search cache object to preserve the namespace, but what implications that this has to contributed modules is unknown.

   // See if this key has been searched for before
-  if (this.cache[searchString]) {
-    return this.owner.found(this.cache[searchString]);
+  if (this.cache['drupal_' + searchString]) {
+    return this.owner.found(this.cache['drupal_' + searchString]);
   }

The following patch uses this approach.

I'll test against a Drupal 7 install in a few hours. Both use the var cache = {} so I would assume that this is an issue with D7 HEAD to.

Alan

Alan D.’s picture

Title:Typing 'watch' triggers an error» Autocomplete.js errors with Mozilla based browsers, due to a namespace conflicts between search terms and object properties
Project:TaxiSelect» Drupal core
Version:6.x-2.0-alpha1» 6.14
Component:Code» base system
Status:Active» Needs review
Alan D.’s picture

StatusFileSize
new14.96 KB

Added a screenshot of the issue using an autocomplete on the DO issue search page, but all keyword checks were done using the issue settings Project autocomplete on FF3.5

This does not appear to happen on IE. For once, they appear to have got it right!

Alan D.’s picture

Version:6.14» 7.x-dev
StatusFileSize
new1.06 KB
Passed: 14717 passes, 0 fails, 0 exceptions
[ View ]

Confirming that this is an issue with Drupal 7 HEAD. New patch is against this.

Francewhoa’s picture

Title:Typing 'watch' triggers an error» Autocomplete.js errors with Mozilla based browsers, due to a namespace conflicts between search terms and object properties
Version:6.14» 7.x-dev
Status:Needs review» Reviewed & tested by the community
StatusFileSize
new33.81 KB
new26.62 KB
new52.87 KB
new13.41 KB
new14.21 KB
new15.93 KB

Confirming that patch in #7 works. Thanks Alan :)

Tested with.
-Drupal 7 (September 9, 2009 - 05:11) fresh install.
-Garland theme.
-Firefox 3, Internet Explorer 7, Opera 10, Safari 4.
-Site OS: Ubuntu Server 8.04 LTS
-End user OS: Windows XP

webchick’s picture

Status:Reviewed & tested by the community» Needs review

Ha! What a funny problem! I was able to sort of reproduce this in D7. Instead of getting [object Object] though, I get 'prototype' when I enter 'watch' and click on the barely visible drop-down.

Another bug I ran into is if you type in something that's not found, and click the down arrow, then tab out of the field, you get 'undefined'. But this happens with or without this patch.

I'm curious, is there a way to name-space these that's more specific to the autocomplete widget (machine-readable ID or similar) than a generic 'drupal_' placeholder? In general, we try and avoid hard-coding 'drupal' assumptions in any user-facing code. I'm also not sure what effect this has if there is more than one autocomplete field on a form (though probably none, since only one of these can be typed in at once).

Alan D.’s picture

StatusFileSize
new1.05 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in autocomplete-cache-namespace_0.patch.
[ View ]

The object is an internal property of the AutoComplete DataBase object that is created for each URI (if I'm reading the JScript correctly) so it shouldn't be used anywhere else.

E.g. acdb[uri] = new Drupal.ACDB(uri);

Happy to change but I do not think that it needs any special treatment for the above reason. 'acdb_' + searchString or 'acdb_cache_' + searchString ?

I mimicked the arrow bug, but I haven't the time to look at it. This is definitely another issue.

The attached patch uses 'acdb_' + searchString.

webchick’s picture

Oh. So that's what ACDB stands for. Thanks! :)

And sorry, I didn't ask my question clearly enough. What I'm basically wondering is whether there's something like a this.parent.getId() (excuse my horrible pseudocode) which we could use for this prefix? So in the case of the autocomplete username field on the node add/edit form, it'd be "name_XXX" and for taxonomy it'd be... oh dear lord... taxonomy_tags[zxx][value]_XXXX :P ok so maybe not the ID but... something about the autocomplete instance that would uniquely identify it.

Basically, I'm just a little concerned about what happens if I have a user "kitten" and a taxonomy term "kitten"; how does this affect the cache if they're both using the same prefix for the value?

Alan D.’s picture

Each have their own autocomplete ACDB object, as these are based on the URI (See where the behaviour attaches ~lines 8), if I'm reading the JScript correctly.

E.g. Using the term & user autocomplete as examples, (with made up URLs), the caches will be different.

acdb['taxonomy/autocomplete/3'].cache

acdb['user/autocomplete'].cache

Each with their own cache object, so there should be no overlap, and if there was (eg: two user autocompletes), the results would be the same anyway as they would be sharing the same acdb object & URI. I was worried about adding a parsed id based prefix which wasn't needed in case it created other bugs... Call me cautious

casey’s picture

Component:base system» javascript
Francewhoa’s picture

Status:Needs review» Reviewed & tested by the community
StatusFileSize
new41.95 KB

Confirming that patch in #10 works. Thanks Alan :)

Find attached screeshot to see result.

Tested with.
-Search with words: wat, watc, watches
-Drupal 7 (7.0-alpha1) fresh install.
-Garland theme.
-Firefox 3.0.17
-Site OS: Ubuntu Server 8.04 LTS
-End user OS: Ubuntu Desktop 8.04 LTS

rfay’s picture

subscribing

realityloop’s picture

#10: autocomplete-cache-namespace.patch queued for re-testing.

Status:Reviewed & tested by the community» Needs work

The last submitted patch, autocomplete-cache-namespace.patch, failed testing.

Alan D.’s picture

Status:Needs work» Needs review
StatusFileSize
new1.03 KB
PASSED: [[SimpleTest]]: [MySQL] 26,583 pass(es).
[ View ]

Dumb patch bots - only some work with Windows line endings....

Re-rolled using UNIX line endings, nothing else has changed.

Status:Needs review» Needs work

The last submitted patch, 590148-18-autocomplete-cache-namespace.patch, failed testing.

Alan D.’s picture

Status:Needs work» Needs review
rfay’s picture

Wow, lost track of this one. Let's get this fixed.

rfay’s picture

Version:7.x-dev» 8.x-dev
Issue tags:+needs backport to D6, +needs backport to D7

Oh so sorry to do this. Has to go into D8 first.

RobLoach’s picture

Francewhoa’s picture

Thanks for following up rfay :)

Alan D.’s picture

Status:Needs review» Closed (duplicate)

A much cleaner solution is here #784670: autocomplete.js can iterate over functions in Array objects. Worth voting for even if JQuery UI Autocomplete makes it into D8.