From 69de7e3fce5f1c993ac01dd27364d17a6feb6c74 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 11 Aug 2014 09:23:52 +1200 Subject: [PATCH] BUG Fix incorrect parsing of HTML content --- admin/javascript/LeftAndMain.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/admin/javascript/LeftAndMain.js b/admin/javascript/LeftAndMain.js index 4650f1d96..c772076f6 100644 --- a/admin/javascript/LeftAndMain.js +++ b/admin/javascript/LeftAndMain.js @@ -585,11 +585,14 @@ jQuery.noConflict(); var newFragments = {}, newContentEls; // If content type is text/json (ignoring charset and other parameters) - if(xhr.getResponseHeader('Content-Type').match(/^text\/json[ \t]*;?/i)) { + if(xhr.getResponseHeader('Content-Type').match(/^((text)|(application))\/json[ \t]*;?/i)) { newFragments = data; } else { + // Fall back to replacing the content fragment if HTML is returned - $data = $(data); + var fragment = document.createDocumentFragment(); + jQuery.clean( [ data ], document, fragment, [] ); + $data = $(jQuery.merge( [], fragment.childNodes )); // Try and guess the fragment if none is provided // TODO: data-pjax-fragment might actually give us the fragment. For now we just check most common case