Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you include a JS script where you extend a prototype of an Array object, like so:
Array.prototype.delete_first = function(obj) {
var i = this.indexOf(obj);
if (i >= 0)
this.splice(i,1);
return this;
};
It gets called on ajax requests from admin pages, like when you press "add another item" in edit node form.
This is the call stack:
delete_first(obj=undefined)spike.js?m2024q (line 35)
abort(h="ajax_html_ids[]", l=function())jquery.js?v=1.4.4 (line 142)
handleError()jquery.js?v=1.4.4 (line 143)
nodeName(j=[Object { name="title", value="test"}, Object { name="changed", value="1333726326"}, Object { name="form_build_id", value="form-LzyzUKCsToYFt2eB0w-FQAWTojlXCDM_C3s2iPI7KFM"}, 161 more...], s=function(), v=Object { name="ajax_html_ids[]", value=function()})jquery.js?v=1.4.4 (line 34)
abort(a=[Object { name="title", value="test"}, Object { name="changed", value="1333726326"}, Object { name="form_build_id", value="form-LzyzUKCsToYFt2eB0w-FQAWTojlXCDM_C3s2iPI7KFM"}, 161 more...], b=undefined)jquery.js?v=1.4.4 (line 143)
ajaxSubmit(a=Object { url="/system/ajax", type="POST", iframeSrc="about:blank", more...})jquery...?v=2.52 (line 12)
eventResponse(element=input#edit-field-neurocenter-und-add-more.field-add-more-submit Add another item, event=Object { originalEvent=Event mousedown, type="mousedown", timeStamp=1333726901359, more...})ajax.js?v=7.12 (line 251)
to the element event. $(event=Object { originalEvent=Event mousedown, type="mousedown", timeStamp=1333726901359, more...})ajax.js?v=7.12 (line 178)
handle(a=Object { originalEvent=Event mousedown, type="mousedown", timeStamp=1333726901359, more...})jquery.js?v=1.4.4 (line 64)
add()jquery.js?v=1.4.4 (line 58)
Comment | File | Size | Author |
---|---|---|---|
#4 | testm.tar_.gz | 419 bytes | akamaus |
#2 | core-js-filter-for-ajax-1518012-2.patch | 535 bytes | nod_ |
Comments
Comment #1
nod_The problem is with an unfiltered
for
loop inDrupal.ajax.prototype.success
.Comment #2
nod_Please test to confirm it's solving the bug in your case.
Comment #3
jcisio CreditAttribution: jcisio commentedCan't not reproduce on a vanilla Drupal.
Comment #4
akamaus CreditAttribution: akamaus commentedI'm pretty sure the bug is there. I've just retested on vanilla D7.12 (standard profile). Steps to reproduce:
Comment #5
nod_Ok I can reproduce, that is not where I expected the problem would be. It happens before the ajax call so it's an unfiltered for in the form code somewhere. Don't have time to dig deeper just yet. Anyway it's confirmed, we can do something about it now :)
Also this is a D7 only issue, D8 JS has been much more cleaned up and this bug doesn't happen. Also it's in my backyard, not the ajax system.
The best way to correct this bug would be to review/reroll the patch #1428524-22: Replace all $.each() with filtered for loop :)
Comment #6
nod_Actuall, closing this one since the other patch will fix this bug.
Comment #7
hngu_shareaholic CreditAttribution: hngu_shareaholic commentedHi there, are there any plans to apply this patch to Drupal 7 code base itself? I am writing a module that would uses a JS library which loads things into Array.prototype. Currently, the module will cause errors in D7.
Comment #8
nod_Feel free to reopen and have a D7 patch. Happy to review.
Comment #9
hngu_shareaholic CreditAttribution: hngu_shareaholic commentedBefore I do that, I am hoping to get some thoughts about what I found.
First of all, I have a module which inserts a JS library that adds additional functions to Array's prototype property.
When a user has modules that uses AJAX or AJAX form submit from Drupal's default install, it would throw an error because the array prototype functions are being called. I traced it to jquery.form.js in the following lines:
The line where it checks if options.data[n] is an instance of Array, it does a for-in on that Array object which adds the prototype functions to variable a. It should avoid iterating the prototype object. Can anyone verify this? I may be looking at an old copy of jquery.form.js or something. I looked at the latest jquery.form.js code and it does not have this issue.
Comment #10
bumpshoveit CreditAttribution: bumpshoveit commentedflag