(attrStr, options)
| 410 | //attr, ="sd", a="amit's", a="sd"b="saf", ab cd="" |
| 411 | |
| 412 | function validateAttributeString(attrStr, options) { |
| 413 | //console.log("start:"+attrStr+":end"); |
| 414 | |
| 415 | //if(attrStr.trim().length === 0) return true; //empty string |
| 416 | |
| 417 | const matches = scanAttributeTokens(attrStr); |
| 418 | const attrNames = {}; |
| 419 | |
| 420 | for (let i = 0; i < matches.length; i++) { |
| 421 | if (matches[i][1].length === 0) { |
| 422 | //nospace before attribute name: a="sd"b="saf" |
| 423 | return getErrorObject('InvalidAttr', "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i])) |
| 424 | } else if (matches[i][3] !== undefined && matches[i][4] === undefined) { |
| 425 | return getErrorObject('InvalidAttr', "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i])); |
| 426 | } else if (matches[i][3] === undefined && !options.allowBooleanAttributes) { |
| 427 | //independent attribute: ab |
| 428 | return getErrorObject('InvalidAttr', "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i])); |
| 429 | } |
| 430 | /* else if(matches[i][6] === undefined){//attribute without value: ab= |
| 431 | return { err: { code:"InvalidAttr",msg:"attribute " + matches[i][2] + " has no value assigned."}}; |
| 432 | } */ |
| 433 | const attrName = matches[i][2]; |
| 434 | if (!validateAttrName(attrName)) { |
| 435 | return getErrorObject('InvalidAttr', "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i])); |
| 436 | } |
| 437 | if (!Object.prototype.hasOwnProperty.call(attrNames, attrName)) { |
| 438 | //check for duplicate attribute. |
| 439 | attrNames[attrName] = 1; |
| 440 | } else { |
| 441 | return getErrorObject('InvalidAttr', "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i])); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | return true; |
| 446 | } |
| 447 | |
| 448 | function validateNumberAmpersand(xmlData, i) { |
| 449 | let re = /\d/; |
no test coverage detected