Skip to content

Commit 6e5ad19

Browse files
Added additional error conditions
1 parent 70f0bcb commit 6e5ad19

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

lib/js2xmlparser.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
if (typeof root !== "string") {
2727
throw new Error("root element must be a string");
2828
}
29+
else if (root === "") {
30+
throw new Error("root element cannot be empty");
31+
}
2932

3033
// Error checking and variable initialization for options
3134
if (typeof options === "object" && options !== null) {
@@ -106,6 +109,10 @@
106109
throw new Error("data must be an object or a string");
107110
}
108111

112+
if (Object.prototype.toString.call(data) === "[object Array]") {
113+
throw new Error("data cannot be an array");
114+
}
115+
109116
if (typeof data === "string") {
110117
data = JSON.parse(data);
111118
}

0 commit comments

Comments
 (0)