Skip to content

Commit

Permalink
Throw error if XPath expression unspecified
Browse files Browse the repository at this point in the history
  • Loading branch information
JLRishe committed Dec 16, 2023
1 parent d1625a4 commit d5bf3d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,18 @@ describe('xpath', () => {
});
});

describe('error handling', () => {
it('should reject unspecified expression', () => {
for (let expr of [null, undefined, '']) {
assert.throws(() => {
xpath.parse(expr);
}, {
message: 'XPath expression unspecified'
});
}
});
});

describe('Node type tests', () => {
it('should correctly identify a Node of type Element', () => {
var doc = parseXml('<book />');
Expand Down
4 changes: 4 additions & 0 deletions xpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,10 @@ var xpath = (typeof exports === 'undefined') ? {} : exports;
XPathParser.ACCEPT = 'a';

XPathParser.prototype.parse = function (s) {
if (!s) {
throw new Error('XPath expression unspecified');
}

var types;
var values;
var res = this.tokenize(s);
Expand Down

0 comments on commit d5bf3d9

Please sign in to comment.