/*
 * Copyright (c) 2018, 2025, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const RULE_NAME="spoc-dom-manip-inv-tag";const TAG_OK="@HTMLUpdateOK";const TAG_REVIEW="@HTMLUpdateReview";const TAG_XSS_FALSE_POSITIVE="@XSSFalsePositive";const TAG_RANDOM="@RandomNumberOK";const TAG_OK_LC="@htmlupdateok";const TAG_REVIEW_LC="@htmlupdatereview";const TAG_XSS_FALSE_POSITIVE_LC="@xssfalsepositive";const TAG_RANDOM_LC="@randomnumberok";const REGEX=/@HTML/gi;const REGEX2=/@XSS/gi;const REGEX3=/@Rand/gi;function Rule(){};Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return"Finds all uses of SPOC tags with incorrect case"};Rule.prototype.getDescription=function(){return"Finds all uses of SPOC tags '@HTMLUpdateOK', '@HTMLUpdateReview', '@XSSFalsePositive' and '@RandomNumberOK' with incorrect case"};Rule.prototype.register=function(){return{"file":_scan}};function _scan(context){var data=context.data,tag,lcTag,s,issue,result,indices=[],i,x;REGEX.lastIndex=0;while(result=REGEX.exec(data)){indices.push(result.index)}REGEX2.lastIndex=0;while(result=REGEX2.exec(data)){indices.push(result.index)}REGEX3.lastIndex=0;while(result=REGEX3.exec(data)){indices.push(result.index)}for(i=0;i<indices.length;i++){x=indices[i];tag=_getTag(context,data,x);lcTag=tag.toLowerCase();if(lcTag.startsWith(TAG_OK_LC)||lcTag.startsWith(TAG_REVIEW_LC)||lcTag.startsWith(TAG_XSS_FALSE_POSITIVE_LC)||lcTag.startsWith(TAG_RANDOM_LC)){s=lcTag.substring(lcTag.length-1);if(s!=="k"&&s!=="w"&&s!=="e"){issue=new context.Issue("Remove trailing extraneous character(s) from '"+tag+"'");_updatePosition(context,issue,data,x,x+tag.length);context.reporter.addIssue(issue,context);continue}}else{issue=new context.Issue("Invalid security tag - '"+tag+"'");_updatePosition(context,issue,data,x,x+tag.length);context.reporter.addIssue(issue,context);continue}if(tag!==TAG_OK&&tag!==TAG_REVIEW&&tag!==TAG_XSS_FALSE_POSITIVE&&tag!==TAG_RANDOM&&!lcTag.startsWith(TAG_REVIEW_LC)){issue=new context.Issue("Invalid security tag case - '"+tag+"' - should be "+(lcTag.includes("review")?TAG_REVIEW:lcTag.includes("xss")?TAG_XSS_FALSE_POSITIVE:lcTag.includes("random")?TAG_RANDOM:TAG_OK));_updatePosition(context,issue,data,x,x+tag.length);context.reporter.addIssue(issue,context)}}};function _getTag(context,data,x){var i=context.utils.utils.getIndexToWhitespace(data,x);return data.substring(x,i)};function _updatePosition(context,issue,data,indexStart,indexEnd){var rowcol=context.utils.utils.getRowColFromIndex(data,indexStart);issue.setPosition(rowcol.row,rowcol.col,indexStart,indexEnd)};module.exports=Rule;