From 8969732518470a7f8e654d5bc5be0b0076cb0b87 Mon Sep 17 00:00:00 2001 From: Michał Gołębiowski-Owczarek Date: Tue, 8 Dec 2020 11:22:21 +0100 Subject: Core: Report browser errors in parseXML Fixes gh-4784 Closes gh-4816 --- src/core/parseXML.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/core') diff --git a/src/core/parseXML.js b/src/core/parseXML.js index 715f59f1f..482545aaf 100644 --- a/src/core/parseXML.js +++ b/src/core/parseXML.js @@ -2,7 +2,7 @@ import jQuery from "../core.js"; // Cross-browser xml parsing jQuery.parseXML = function( data ) { - var xml; + var xml, parserErrorElem; if ( !data || typeof data !== "string" ) { return null; } @@ -11,12 +11,17 @@ jQuery.parseXML = function( data ) { // IE throws on parseFromString with invalid input. try { xml = ( new window.DOMParser() ).parseFromString( data, "text/xml" ); - } catch ( e ) { - xml = undefined; - } + } catch ( e ) {} - if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) { - jQuery.error( "Invalid XML: " + data ); + parserErrorElem = xml && xml.getElementsByTagName( "parsererror" )[ 0 ]; + if ( !xml || parserErrorElem ) { + jQuery.error( "Invalid XML: " + ( + parserErrorElem ? + jQuery.map( parserErrorElem.childNodes, function( el ) { + return el.textContent; + } ).join( "\n" ) : + data + ) ); } return xml; }; -- cgit v1.2.3