<commit_before>/**
 * Implements the CFML Function getbasetagdata
 */
package railo.runtime.functions.other;

import javax.servlet.jsp.tagext.Tag;

import railo.commons.lang.StringUtil;
import railo.runtime.PageContext;
import railo.runtime.exp.ExpressionException;
import railo.runtime.exp.PageException;
import railo.runtime.ext.function.Function;
import railo.runtime.tag.CFTag;
import railo.runtime.tag.CFTagCore;
import railo.runtime.type.Struct;

public final class GetBaseTagData implements Function {
	
    public static Struct call(PageContext pc , String tagName) throws PageException {
		return call(pc,tagName,-1);
	}
	
    public static Struct call(PageContext pc , String tagName, double minLevel) throws PageException {
    	//print.out("tagname:"+tagName);
    	CFTag tag=getParentCFTag(pc.getCurrentTag(), tagName, (int)minLevel);
        if(tag==null) throw new ExpressionException("can't find base tag with name ["+tagName+"]");
        return tag.getVariablesScope();
	}
    
    public synchronized static CFTag getParentCFTag(Tag srcTag,String trgTagName, int minLevel) {
        String pureName=trgTagName;
        int level=0;
        CFTag cfTag;
        while(srcTag!=null) {
        	// cftag
        	if(srcTag instanceof CFTag && minLevel<=++level) {
                cfTag=(CFTag)srcTag;
                if(cfTag instanceof CFTagCore){
                	CFTagCore tc=(CFTagCore) cfTag;
                	if((tc.getName()+"").equalsIgnoreCase(pureName))
                		return cfTag;
                	if(StringUtil.startsWithIgnoreCase(pureName,"cf")) {
                        pureName=pureName.substring(2);
                    }
                	if((tc.getName()+"").equalsIgnoreCase(pureName))
                		return cfTag;
                }
                else if( cfTag.getAppendix().equalsIgnoreCase(pureName)) {
                    return cfTag;
                }
                else if(StringUtil.startsWithIgnoreCase(pureName,"cf_")) {
                    pureName=pureName.substring(3);
                    if(cfTag.getAppendix().equalsIgnoreCase(pureName)) 
                        return cfTag;
                }
            }
            srcTag=srcTag.getParent();
            
        }
        return null;
    }
}<commit_msg>fixed issue with wrong minlevel handling<commit_after>/**
 * Implements the CFML Function getbasetagdata
 */
package railo.runtime.functions.other;

import javax.servlet.jsp.tagext.Tag;

import railo.commons.lang.StringUtil;
import railo.runtime.PageContext;
import railo.runtime.exp.ExpressionException;
import railo.runtime.exp.PageException;
import railo.runtime.ext.function.Function;
import railo.runtime.tag.CFTag;
import railo.runtime.tag.CFTagCore;
import railo.runtime.type.Struct;

public final class GetBaseTagData implements Function {
	
	private static final long serialVersionUID = -7016207088098049143L;

	public static Struct call(PageContext pc , String tagName) throws PageException {
		return call(pc,tagName,-1);
	}
	
    public static Struct call(PageContext pc , String tagName, double minLevel) throws PageException {
    	CFTag tag=getParentCFTag(pc.getCurrentTag(), tagName, (int)minLevel);
        if(tag==null) throw new ExpressionException("can't find base tag with name ["+tagName+"]");
        return tag.getVariablesScope();
	}
    
    public synchronized static CFTag getParentCFTag(Tag tag,String trgTagName, int minLevel) {
        String pureName=trgTagName;
        int level=0;
        CFTag cfTag;
        while(tag!=null) {
        	if(tag instanceof CFTag && minLevel<=(level++)) {
            	cfTag=(CFTag)tag;
                if(cfTag instanceof CFTagCore){
            	
                	CFTagCore tc=(CFTagCore) cfTag;
                	
                	if((tc.getName()+"").equalsIgnoreCase(pureName))
                		return cfTag;
                	if(StringUtil.startsWithIgnoreCase(pureName,"cf")) {
                        pureName=pureName.substring(2);
                    }
                	if((tc.getName()+"").equalsIgnoreCase(pureName))
                		return cfTag;
                }
                else if( cfTag.getAppendix().equalsIgnoreCase(pureName)) {
                    return cfTag;
                }
                else if(StringUtil.startsWithIgnoreCase(pureName,"cf_")) {
                    pureName=pureName.substring(3);
                    if(cfTag.getAppendix().equalsIgnoreCase(pureName)) 
                        return cfTag;
                }
            }
        	tag=tag.getParent();
        }
        return null;
    }
}
{'fraction_non_alphanumeric': 0.10102552912939122, 'fraction_numerical': 0.005891337551821951, 'mean_word_length': 2.232722143864598, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7662564', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1288, 'n_words': 251}