Bug Tracker

Opened 10 years ago

Closed 10 years ago

#14316 closed bug (invalid)

Deserialization invalid HTML issue inside the "buildFragment"

Reported by: [email protected] Owned by: [email protected]
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:



My code works with the user data potentially containing non-valid HTML. I've found the bug which reproduced in the jsfiddle when jQuery throws an exception when trying to build fragment.


I saw the same issue http://bugs.jquery.com/ticket/13976 has been done but the fix doesn't work with my data set.

Please check it out.

I'll be waiting for your answer,


Change History (3)

comment:1 Changed 10 years ago by dmethvin

Owner: set to [email protected]
Status: newpending

What result would you ideally want from invalid input?

comment:2 Changed 10 years ago by anonymous

Ideally do not throw an exception.

Possible fix is:

diff --git a/src/manipulation.js b/src/manipulation.js
index 89cc46c..c1e6c09 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -388,7 +388,8 @@ jQuery.extend({
                                        // Deserialize a standard representation
                                        tag = ( rtagName.exec( elem ) || ["", ""] )[ 1 ].toLowerCase();
                                        wrap = wrapMap[ tag ] || wrapMap._default;
-                                       tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
+                                       tmp.innerHTML = elem.replace( rxhtmlTag, "<$1></$2>" );
+                                       tmp.innerHTML = wrap[ 1 ] + tmp.innerHTML + wrap[ 2 ];
                                        // Descend through wrappers to the right content
                                        j = wrap[ 0 ];

Invalid HTML issue should be resolved here by http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#html-fragment-serialization-algorithm

comment:3 Changed 10 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Note: See TracTickets for help on using tickets.