Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions spec/validator_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,41 @@ describe("XMLParser", function() {
});

it("should validate self closing tags", function() {
const xmlData = "<rootNode><validtag1 /><validtag2/><validtag3 with='attrib'/></rootNode>";
const xmlData = "<rootNode><validtag1 /><validtag2/><validtag3 with='attrib'/><validtag4 />text<validtag5/>text</rootNode>";
const result = validator.validate(xmlData);
expect(result).toBe(true);
});

it("should not validate self closing tags", function() {
const xmlData = "<rootNode><validtag1/><invalid tag/><validtag3 with='attrib'/></rootNode>";
const expected = {code: "InvalidAttr", msg: "boolean attribute tag is not allowed."};
it("should not consider these as self closing tags", function() {
let xmlData = "<rootNode><validtag1/><invalid tag/><validtag3 with='attrib'/></rootNode>";
let expected = {code: "InvalidAttr", msg: "boolean attribute tag is not allowed."};

const result = validator.validate(xmlData).err;
let result = validator.validate(xmlData).err;
//console.log(JSON.stringify(result,null,4));
expect(result).toEqual(expected);

xmlData = "<rootNode><notSelfClosing/ ></rootNode>";
expected = {code: "InvalidAttr", msg: "attribute / has no space in starting."};

result = validator.validate(xmlData).err;
expect(result).toEqual(expected);
});

/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is commented out because it doesn't pass due to another bug. This is addressed in #205

it("should correctly identify self closing tags", function() {
let xmlData = "<rootNode><in/valid></in/valid></rootNode>";
let expected = {code: "InvalidTag", msg: "Tag in/valid is an invalid name."};

let result = validator.validate(xmlData).err;
expect(result).toEqual(expected);

xmlData = "<rootNode><in#valid/></rootNode>";
expected = {code: "InvalidTag", msg: "Tag in#valid is an invalid name."};

result = validator.validate(xmlData).err;
expect(result).toEqual(expected);
});
*/

it("should not validate xml string when closing tag is different", function() {
const xmlData = "<rootNode></rootnode>";
Expand Down
2 changes: 1 addition & 1 deletion src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ exports.validate = function(xmlData, options) {
if (tagName[tagName.length - 1] === '/') {
//self closing tag without attributes
tagName = tagName.substring(0, tagName.length - 1);
continue;
i--;
}
if (!validateTagName(tagName, regxTagName)) {
return {err: {code: 'InvalidTag', msg: 'Tag ' + tagName + ' is an invalid name.'}};
Expand Down