/*
 * 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="oj-html-self-close";const SHORT="Do not self-close non-void elements.";const DESCRIPT="Do not self-close non-void elements, e.g.  &lt;div/&gt; or &lt;span/&gt;";function Rule(){};Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return SHORT};Rule.prototype.getDescription=function(){return DESCRIPT};Rule.prototype.register=function(regCtx){this._utils=regCtx.utils.utils;return{elem:this._onElem}};Rule.prototype._onElem=function(ruleCtx,tag){var tag,n,issue;var DomUtils;DomUtils=ruleCtx.utils.DomUtils;n=ruleCtx.tagNode;if(!DomUtils.isSvgElem(tag)){if(!DomUtils.isCommonElem(tag)||!DomUtils.isSelfClosingTag(tag)){if(this._isClosed(ruleCtx.data.substring(n.startIndex,n.endIndex+1),n)){issue=new ruleCtx.Issue(`Invalid self-closure of non-void tag '<${tag}/>'`);ruleCtx.reporter.addIssue(issue,ruleCtx)}}}};Rule.prototype._isClosed=function(data,node){var c,x,i;data=_removeAttribs(data,node);if(!data){return false}data=data.trim();if(data.charAt(0)!=="<"){return false}x=_findClose(data);if(x>=0){data=data.substring(0,x+1)}if(data.charAt(data.length-1)===">"){for(i=data.length-2;i>1;i--){c=data.charAt(i);if(this._utils.isWhitespace(c)){continue}return c==="/"}}return false};function _findClose(data){var x;x=data.indexOf(">");return x<0?0:x};function _removeAttribs(data,node){var attrs,attr,val,re;if(!node.attribs){return data}attrs=node.attribs;for(attr in attrs){val=attrs[attr];try{re=new RegExp(attr)}catch(e){re=null}if(!re){return null}data=data.replace(re,"");val=val.replace(/[.*+\-?^${}()|[\]\\]/g,"\\$&");re=new RegExp(val);data=data.replace(re,"")}data=data.replace(/[\"\'\=\[\(\{\}\)\]\s#,_]/g,"");return data};module.exports=Rule;