/// <summary> Validates a basic selector against the policy /// /// </summary> /// <param name="selector">the object representation of the selector /// </param> /// <param name="results">the <code>CleanResults</code> object to add any error /// messages to /// </param> /// <returns> true if this selector name is valid; false otherwise /// </returns> private bool validateSimpleSelector(SimpleSelector selector, CleanResults results) { // ensure the name follows the valid pattern and is not blacklisted // by the exclusion pattern. // NOTE: intentionally using non-short-circuited AND operator to // generate all relevant error messages //return policy.getRegularExpression("cssElementSelector").Pattern.matcher(selector.toString().toLowerCase()).matches() & !policy.getRegularExpression("cssElementExclusion").Pattern.matcher(selector.toString().toLowerCase()).matches(); string name = ((ElementSelector)selector).getLocalName().ToLower(); string css = (policy.getRegularExpression("cssElementSelector") != null ? policy.getRegularExpression("cssElementSelector") : ""); string exc = (policy.getRegularExpression("cssElementExclusion") != null ? policy.getRegularExpression("cssElementExclusion") : ""); css = "^" + css + "$"; exc = "^" + exc + "$"; Match m1 = Regex.Match(name, css); Match m2 = Regex.Match(name, exc); return(m1.Success & !m2.Success); }
/// <summary> Validates a basic selector against the policy /// /// </summary> /// <param name="selector">the object representation of the selector /// </param> /// <param name="results">the <code>CleanResults</code> object to add any error /// messages to /// </param> /// <returns> true if this selector name is valid; false otherwise /// </returns> private bool validateSimpleSelector(SimpleSelector selector, CleanResults results) { // ensure the name follows the valid pattern and is not blacklisted // by the exclusion pattern. // NOTE: intentionally using non-short-circuited AND operator to // generate all relevant error messages //return policy.getRegularExpression("cssElementSelector").Pattern.matcher(selector.toString().toLowerCase()).matches() & !policy.getRegularExpression("cssElementExclusion").Pattern.matcher(selector.toString().toLowerCase()).matches(); string name = ((ElementSelector)selector).getLocalName().ToLower(); string css = (policy.getRegularExpression("cssElementSelector") != null ? policy.getRegularExpression("cssElementSelector") : ""); string exc = (policy.getRegularExpression("cssElementExclusion") != null ? policy.getRegularExpression("cssElementExclusion") : ""); css = "^" + css + "$"; exc = "^" + exc + "$"; Match m1 = Regex.Match(name, css); Match m2 = Regex.Match(name, exc); return m1.Success & !m2.Success; }