mirror of
https://github.com/jquery/jquery.git
synced 2024-12-09 08:04:24 +00:00
Makes parseXML act like parseJSON when given an empty or non-string input: now returns null rather than throwing an exception. Incidently fixes #10527. Unit tests added.
This commit is contained in:
parent
bd56456b1e
commit
d30859eb6b
@ -557,6 +557,9 @@ jQuery.extend({
|
|||||||
|
|
||||||
// Cross-browser xml parsing
|
// Cross-browser xml parsing
|
||||||
parseXML: function( data ) {
|
parseXML: function( data ) {
|
||||||
|
if ( typeof data !== "string" || !data ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
var xml, tmp;
|
var xml, tmp;
|
||||||
try {
|
try {
|
||||||
if ( window.DOMParser ) { // Standard
|
if ( window.DOMParser ) { // Standard
|
||||||
|
@ -1113,7 +1113,7 @@ test("jQuery.parseJSON", function(){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery.parseXML", 4, function(){
|
test("jQuery.parseXML", 8, function(){
|
||||||
var xml, tmp;
|
var xml, tmp;
|
||||||
try {
|
try {
|
||||||
xml = jQuery.parseXML( "<p>A <b>well-formed</b> xml string</p>" );
|
xml = jQuery.parseXML( "<p>A <b>well-formed</b> xml string</p>" );
|
||||||
@ -1131,6 +1131,18 @@ test("jQuery.parseXML", 4, function(){
|
|||||||
} catch( e ) {
|
} catch( e ) {
|
||||||
strictEqual( e.message, "Invalid XML: <p>Not a <<b>well-formed</b> xml string</p>", "invalid xml detected" );
|
strictEqual( e.message, "Invalid XML: <p>Not a <<b>well-formed</b> xml string</p>", "invalid xml detected" );
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
xml = jQuery.parseXML( "" );
|
||||||
|
strictEqual( xml, null, "empty string => null document" );
|
||||||
|
xml = jQuery.parseXML();
|
||||||
|
strictEqual( xml, null, "undefined string => null document" );
|
||||||
|
xml = jQuery.parseXML( null );
|
||||||
|
strictEqual( xml, null, "null string => null document" );
|
||||||
|
xml = jQuery.parseXML( true );
|
||||||
|
strictEqual( xml, null, "non-string => null document" );
|
||||||
|
} catch( e ) {
|
||||||
|
ok( false, "empty input throws exception" );
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery.sub() - Static Methods", function(){
|
test("jQuery.sub() - Static Methods", function(){
|
||||||
|
Loading…
Reference in New Issue
Block a user