(attrStr, options)
| 317 | //attr, ="sd", a="amit's", a="sd"b="saf", ab cd="" |
| 318 | |
| 319 | function validateAttributeString(attrStr, options) { |
| 320 | //console.log("start:"+attrStr+":end"); |
| 321 | |
| 322 | //if(attrStr.trim().length === 0) return true; //empty string |
| 323 | |
| 324 | const matches = getAllMatches(attrStr, validAttrStrRegxp); |
| 325 | const attrNames = {}; |
| 326 | |
| 327 | for (let i = 0; i < matches.length; i++) { |
| 328 | if (matches[i][1].length === 0) { |
| 329 | //nospace before attribute name: a="sd"b="saf" |
| 330 | return getErrorObject('InvalidAttr', "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i])) |
| 331 | } else if (matches[i][3] !== undefined && matches[i][4] === undefined) { |
| 332 | return getErrorObject('InvalidAttr', "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i])); |
| 333 | } else if (matches[i][3] === undefined && !options.allowBooleanAttributes) { |
| 334 | //independent attribute: ab |
| 335 | return getErrorObject('InvalidAttr', "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i])); |
| 336 | } |
| 337 | /* else if(matches[i][6] === undefined){//attribute without value: ab= |
| 338 | return { err: { code:"InvalidAttr",msg:"attribute " + matches[i][2] + " has no value assigned."}}; |
| 339 | } */ |
| 340 | const attrName = matches[i][2]; |
| 341 | if (!validateAttrName(attrName)) { |
| 342 | return getErrorObject('InvalidAttr', "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i])); |
| 343 | } |
| 344 | if (!Object.prototype.hasOwnProperty.call(attrNames, attrName)) { |
| 345 | //check for duplicate attribute. |
| 346 | attrNames[attrName] = 1; |
| 347 | } else { |
| 348 | return getErrorObject('InvalidAttr', "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i])); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | return true; |
| 353 | } |
| 354 | |
| 355 | function validateNumberAmpersand(xmlData, i) { |
| 356 | let re = /\d/; |
no test coverage detected