Skip to main content

Bug Tracker

Side navigation

#14316 closed bug (invalid)

Opened August 29, 2013 01:47PM UTC

Closed September 13, 2013 08:37AM UTC

Deserialization invalid HTML issue inside the "buildFragment"

Reported by: drumsuck@gmail.com Owned by: drumsuck@gmail.com
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:
Description

Hi,

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.

http://jsfiddle.net/ynHPn/4/

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,

Thanks

Attachments (0)
Change History (3)

Changed August 29, 2013 01:51PM UTC by dmethvin comment:1

owner: → drumsuck@gmail.com
status: newpending

What result would you ideally want from invalid input?

Changed August 29, 2013 02:09PM UTC by anonymous comment:2

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

Changed September 13, 2013 08:37AM UTC by trac-o-bot comment:3

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!