<commit_before>﻿component implements="system.interfaces.com.irCMS.validation.validator" {
    public validator function init(required string tablePrefix, required string datasource) {
        variables.datasource  = arguments.datasource;
        variables.tablePrefix = arguments.tablePrefix;
        
        this.reload();
        
        return this;
    }
    
    public boolean function reload() {
    	variables.validationRules = {};
    	
    	var qryRules = new Query().setDatasource(variables.datasource)
    	                          .setSQL("  SELECT ruleName, rule, tip, description, country, language "
    	                                 &"    FROM #variables.tablePrefix#_validationRule "
    	                                 &"ORDER BY ruleName, country, language")
    	                          .execute()
    	                          .getResult();
    	
    	for(var i = 1; i <= qryRules.getRecordCount(); i++) {
    		if(! variables.validationRules.keyExists(qryRules.ruleName[i])) {
    		    variables.validationRules[ qryRules.ruleName[i] ] = {};
    	    }
    		
    		if(qryRules.country[i] != '') {
    			variables.validationRules[ qryRules.ruleName[i] ][ qryRules.country[i] ] = {};
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.country[i] ].rule        = qryRules.rule[i];
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.country[i] ].tip         = qryRules.tip[i];
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.country[i] ].description = qryRules.description[i];
    		}
    		else if(qryRules.language[i] != '') {
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.language[i] ] = {};
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.language[i] ].rule        = qryRules.rule[i];
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.language[i] ].tip         = qryRules.tip[i];
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.language[i] ].description = qryRules.description[i];
    		}
    		else {
                variables.validationRules[ qryRules.ruleName[i] ][ 'global' ] = {};
                variables.validationRules[ qryRules.ruleName[i] ][ 'global' ].rule        = qryRules.rule[i];
                variables.validationRules[ qryRules.ruleName[i] ][ 'global' ].tip         = qryRules.tip[i];
                variables.validationRules[ qryRules.ruleName[i] ][ 'global' ].description = qryRules.description[i];
    		}
    	}
    	
    	return true;
    }
    
    public boolean function validate(required string content, required string ruleName, required boolean mandatory = true, string country, string language) {
        if(arguments.mandatory && arguments.content.len() == 0) {
        	return false;
        }
        
        if(! variables.validationRules.keyExists(arguments.ruleName)) {
        	return false;
        }
        
        if(! isNull(arguments.country) && variables.validationRules[arguments.ruleName].keyExists(arguments.country)) {
        	return false;
        }
        else {
        	return this.doValidation(data = arguments.content, rule = variables.validationRules[arguments.ruleName][arguments.country].rule);
        }
        
        if(! isNull(arguments.language) && variables.validationRules[arguments.ruleName].keyExists(arguments.language)) {
            return false;
        }
        else {
            return this.doValidation(data = arguments.content, rule = variables.validationRules[arguments.ruleName][arguments.language].rule);
        }<commit_msg>Fixed two bugs in the validator component<commit_after>﻿component implements="system.interfaces.com.irCMS.validation.validator" {
    public validator function init(required string tablePrefix, required string datasource) {
        variables.datasource  = arguments.datasource;
        variables.tablePrefix = arguments.tablePrefix;
        
        this.reload();
        
        return this;
    }
    
    public boolean function reload() {
    	variables.validationRules = {};
    	
    	var qryRules = new Query().setDatasource(variables.datasource)
    	                          .setSQL("  SELECT ruleName, rule, tip, description, country, language "
    	                                 &"    FROM #variables.tablePrefix#_validationRule "
    	                                 &"ORDER BY ruleName, country, language")
    	                          .execute()
    	                          .getResult();
    	
    	for(var i = 1; i <= qryRules.getRecordCount(); i++) {
    		if(! variables.validationRules.keyExists(qryRules.ruleName[i])) {
    		    variables.validationRules[ qryRules.ruleName[i] ] = {};
    	    }
    		
    		if(qryRules.country[i] != '') {
    			variables.validationRules[ qryRules.ruleName[i] ][ qryRules.country[i] ] = {};
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.country[i] ].rule        = qryRules.rule[i];
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.country[i] ].tip         = qryRules.tip[i];
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.country[i] ].description = qryRules.description[i];
    		}
    		else if(qryRules.language[i] != '') {
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.language[i] ] = {};
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.language[i] ].rule        = qryRules.rule[i];
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.language[i] ].tip         = qryRules.tip[i];
                variables.validationRules[ qryRules.ruleName[i] ][ qryRules.language[i] ].description = qryRules.description[i];
    		}
    		else {
                variables.validationRules[ qryRules.ruleName[i] ][ 'global' ] = {};
                variables.validationRules[ qryRules.ruleName[i] ][ 'global' ].rule        = qryRules.rule[i];
                variables.validationRules[ qryRules.ruleName[i] ][ 'global' ].tip         = qryRules.tip[i];
                variables.validationRules[ qryRules.ruleName[i] ][ 'global' ].description = qryRules.description[i];
    		}
    	}
    	
    	return true;
    }
    
    public boolean function validate(required string content, required string ruleName, required boolean mandatory = true, string country, string language) {
        if(arguments.mandatory && arguments.content.length() == 0) {
        	return false;
        }
        
        if(! variables.validationRules.keyExists(arguments.ruleName)) {
        	return false;
        }
        
        if(! isNull(arguments.country) && variables.validationRules[arguments.ruleName].keyExists(arguments.country)) {
            return this.doValidation(data = arguments.content, rule = variables.validationRules[arguments.ruleName][arguments.country].rule);
        }
        
        if(! isNull(arguments.language) && variables.validationRules[arguments.ruleName].keyExists(arguments.language)) {
            return this.doValidation(data = arguments.content, rule = variables.validationRules[arguments.ruleName][arguments.language].rule);
        }
{'fraction_non_alphanumeric': 0.12020495776208281, 'fraction_numerical': 0.000553939897521119, 'mean_word_length': 2.2902050113895216, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4941669', 'n_tokens_mistral': 2076, 'n_tokens_neox': 2030, 'n_words': 324}