Last modified: 2012-11-02 19:14:14 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T43688, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 41688 - Buggy $.unique function fails for empty arrays, breaking other scripts
Buggy $.unique function fails for empty arrays, breaking other scripts
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
TimedMediaHandler (Other open bugs)
master
All All
: High normal (vote)
: ---
Assigned To: Michael Dale
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-11-02 12:39 UTC by Kevin Israel (PleaseStand)
Modified: 2012-11-02 19:14 UTC (History)
5 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Kevin Israel (PleaseStand) 2012-11-02 12:39:11 UTC
In the MwEmbedSupport extension, MwEmbedModules/MwEmbedSupport/jquery/jquery.mwEmbedUtil.js contains the following buggy code:

        /**
         * Extend Unique to work with strings and number values
         * http://paulirish.com/2010/duck-punching-with-jquery/
         */
        var _oldUnique = $.unique;
    $.unique = function(arr){
        // Do the default behavior only if we got an array of elements
        if (!!arr[0].nodeType){
            return _oldUnique.apply(this,arguments);
        } else {
            // reduce the array to contain no dupes via grep/inArray
            return $.grep(arr,function(v,k){
                return $.inArray(v,arr) === k;
            });
        }
    };

!!arr[0].nodeType causes an exception for empty arrays. This broke one of the Wikipedia user scripts I developed, which uses jquery.ui.tabs.

The proper fix is to put the array-specific code in a separate function rather than trying to monkey patch a function "chiefly used internally by jQuery".

I'm just hesitant to do that myself because of how the TimedMediaHandler code is spread across two Git repositories.
Comment 1 Sumana Harihareswara 2012-11-02 14:19:04 UTC
Thanks for the bug report, PleaseStand! Go ahead and make the fix - just say in the commit message for each of the two commits, "DO NOT MERGE until and unless you're merging with the other half of the fix in (other repository)".  Does that make sense?  Thanks!
Comment 2 Jan Gerber 2012-11-02 15:41:12 UTC
patches for MwEmbedSupport and TimedMediaHandler are in the review queue at:
https://gerrit.wikimedia.org/r/#/c/31386/
https://gerrit.wikimedia.org/r/#/c/31387/
Comment 3 Kevin Israel (PleaseStand) 2012-11-02 19:14:14 UTC
The patches have been merged; closing this bug.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links