Skip to content

Defining any property/function on Object.prototype will cause jQuery's addBack to throw error? #4789

@dotnetprono1

Description

@dotnetprono1

I think this must be a bug of jQuery, a simple custom property/function definition on Object.prototype is just normal (and fairly common). That kind of action should not trigger any bug in any framework. But here it does cause a bug in the jQuery when we use addBack with filter (selector).

So here what I've done before detecting the issue:

//define a simple dummy random property like this (before loading and running the jQuery code)
Object.prototype.xyzxxx = "";

$(function(){
     //just try a query with .addBack with selector
     $("div").addBack("div");
});

Here is the error printed in the console:

Uncaught TypeError: G[o].exec is not a function
at se.tokenize (jquery-3.5.1.min.js:2)
at se.compile (jquery-3.5.1.min.js:2)
at se.select (jquery-3.5.1.min.js:2)
at se (jquery-3.5.1.min.js:2)
at Function.se.matches (jquery-3.5.1.min.js:2)
at Function.S.filter (jquery-3.5.1.min.js:2)
at D (jquery-3.5.1.min.js:2)
at S.fn.init.filter (jquery-3.5.1.min.js:2)
at S.fn.init.addBack (jquery-3.5.1.min.js:2)
at HTMLDocument.<anonymous> (?editor_console=:111)

Note that the addBack without selector will not cause the error.
You can try out the fiddle here https://jsfiddle.net/v8hfmdn3/1/ for detailed error info.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions