Skip to content

Commit

Permalink
Validator: Beautify
Browse files Browse the repository at this point in the history
  • Loading branch information
orgads authored and amitguptagwl committed Jan 26, 2020
1 parent a3436de commit 74b5586
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,12 @@ exports.validate = function (xmlData, options) {
}
//read tagname
let tagName = '';
for (
;
i < xmlData.length &&
for (; i < xmlData.length &&
xmlData[i] !== '>' &&
xmlData[i] !== ' ' &&
xmlData[i] !== '\t' &&
xmlData[i] !== '\n' &&
xmlData[i] !== '\r';
i++
xmlData[i] !== '\r'; i++
) {
tagName += xmlData[i];
}
Expand All @@ -72,9 +69,9 @@ exports.validate = function (xmlData, options) {
}
if (!validateTagName(tagName)) {
let msg;
if(tagName.trim().length === 0) {
if (tagName.trim().length === 0) {
msg = "There is an unnecessary space between tag name and backward slash '</ ..'.";
}else{
} else {
msg = `Tag '${tagName}' is an invalid name.`;
}
return getErrorObject('InvalidTag', msg, getLineNumberForPosition(xmlData, i));
Expand Down Expand Up @@ -112,8 +109,7 @@ exports.validate = function (xmlData, options) {
}

//when there are no more tags, we reached the root level.
if(tags.length == 0)
{
if (tags.length == 0) {
reachedRoot = true;
}
}
Expand All @@ -127,10 +123,10 @@ exports.validate = function (xmlData, options) {
}

//if the root level has been reached before ...
if(reachedRoot === true) {
return getErrorObject('InvalidXml', 'Multiple possible root nodes found.', getLineNumberForPosition(xmlData, i));
if (reachedRoot === true) {
return getErrorObject('InvalidXml', 'Multiple possible root nodes found.', getLineNumberForPosition(xmlData, i));
} else {
tags.push(tagName);
tags.push(tagName);
}
tagFound = true;
}
Expand Down Expand Up @@ -285,7 +281,11 @@ function readAttributeStr(xmlData, i) {
return false;
}

return { value: attrStr, index: i, tagClosed: tagClosed };
return {
value: attrStr,
index: i,
tagClosed: tagClosed
};
}

/**
Expand Down Expand Up @@ -378,14 +378,10 @@ function validateAttrName(attrName) {
return util.isName(attrName);
}

//const startsWithXML = new RegExp("^[Xx][Mm][Ll]");
// startsWith = /^([a-zA-Z]|_)[\w.\-_:]*/;
// const startsWithXML = /^xml/i;

function validateTagName(tagname) {
/*if(util.doesMatch(tagname,startsWithXML)) return false;
else*/
//return !tagname.toLowerCase().startsWith("xml") || !util.doesNotMatch(tagname, regxTagName);
return util.isName(tagname);
return util.isName(tagname) /* && !tagname.match(startsWithXML) */;
}

//this function returns the line number for the character at the given index
Expand Down

0 comments on commit 74b5586

Please sign in to comment.