Bug Tracker

Modify

Ticket #910 (closed bug: fixed)

Opened 6 years ago

Last modified 6 years ago

DOM manipulations with FORM elements fail

Reported by: Renato Owned by:
Priority: major Milestone:
Component: core Version: 1.1
Keywords: Cc:
Blocking: Blocked by:

Description

If you execute this snippet of code, you see the form is not appended, only its children

$("form:first").clone().
appendTo("body");

The problem is in the end of jQuery.clean function at line 498:

if ( arg[0] == undefined )
	r.push( arg );
else
	r = jQuery.merge( r, arg );

In fact, the form element can be used as an array to inspect its inputs, so instead of just pushing the form element, jQuery execute the "else" merging the content of the form element and returning its inputs.

Changing to this code, solves the problem:

if ( arg[0] == undefined || jQuery.nodeName(arg,"form") )
	r.push( arg );
else
	r = jQuery.merge( r, arg );

Attachments

new_test.diff Download (1.1 KB) - added by Renato 6 years ago.
a test for the bug
new_test.2.diff Download (1.1 KB) - added by Renato 6 years ago.
a test for the bug
new_test.3.diff Download (1.1 KB) - added by Renato 6 years ago.
the test
clean.diff Download (520 bytes) - added by brandon 6 years ago.
patch

Change History

Changed 6 years ago by Renato

a test for the bug

Changed 6 years ago by Renato

a test for the bug

Changed 6 years ago by Renato

the test

comment:1 Changed 6 years ago by Renato

Here is the patch with the test code to be added to the test suite

Index: coreTest.js
===================================================================
--- coreTest.js	(revisione 1258)
+++ coreTest.js	(copia locale)
@@ -204,7 +204,7 @@
 });
 
 test("append(String|Element|Array<Element>|jQuery)", function() {
-	expect(9);
+	expect(10);
 	var defaultText = 'Try them out:'
 	var result = $('#first').append('<b>buga</b>');
 	ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
@@ -233,6 +233,10 @@
 	ok( $("#sap").append([]), "Check for appending an empty array." );
 	ok( $("#sap").append(""), "Check for appending an empty string." );
 	ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
+	
+	reset();
+	$("#sap").append(document.getElementById('form'));
+	ok( $("#sap>form").size() == 1, "Check for appending a form" );
 });
 
 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
@@ -678,4 +682,4 @@
 	    //console.log( close[0]); // it's the <a> and not a <span> element
 	    return false;
 	}).click();
-});
 Nessun a-capo alla fine del file
+});

comment:2 Changed 6 years ago by brandon

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in revision 1294.

Thank you for the patch+test.

comment:3 Changed 6 years ago by brandon

  • Status changed from closed to reopened
  • Resolution fixed deleted

Reopening because the fix is causing Safari to crash.

Changed 6 years ago by brandon

patch

comment:4 Changed 6 years ago by brandon

  • Status changed from reopened to closed
  • Resolution set to fixed

Fixed in Revision 1422.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.