diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2020-12-08 11:22:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-08 11:22:21 +0100 |
commit | 8969732518470a7f8e654d5bc5be0b0076cb0b87 (patch) | |
tree | a1157b8f4162af1333756ba45fbb0716ae86997e /src/core | |
parent | fd421097c56696e4c1c4a99c1aae44c59a722be4 (diff) | |
download | jquery-8969732518470a7f8e654d5bc5be0b0076cb0b87.tar.gz jquery-8969732518470a7f8e654d5bc5be0b0076cb0b87.zip |
Core: Report browser errors in parseXML
Fixes gh-4784
Closes gh-4816
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/parseXML.js | 17 |
1 files changed, 11 insertions, 6 deletions
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; }; |