aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core.js3
-rw-r--r--test/unit/core.js14
2 files changed, 16 insertions, 1 deletions
diff --git a/src/core.js b/src/core.js
index 9a551446b..9c8314c91 100644
--- a/src/core.js
+++ b/src/core.js
@@ -557,6 +557,9 @@ jQuery.extend({
// Cross-browser xml parsing
parseXML: function( data ) {
+ if ( typeof data !== "string" || !data ) {
+ return null;
+ }
var xml, tmp;
try {
if ( window.DOMParser ) { // Standard
diff --git a/test/unit/core.js b/test/unit/core.js
index 23642e03d..e87c10664 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -1113,7 +1113,7 @@ test("jQuery.parseJSON", function(){
}
});
-test("jQuery.parseXML", 4, function(){
+test("jQuery.parseXML", 8, function(){
var xml, tmp;
try {
xml = jQuery.parseXML( "<p>A <b>well-formed</b> xml string</p>" );
@@ -1131,6 +1131,18 @@ test("jQuery.parseXML", 4, function(){
} catch( e ) {
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(){