/// <summary> /// Determines whether the specified attribute is allowed. /// </summary> /// <param name="attribute">The attribute.</param> /// <returns><c>true</c> if the attribute is allowed; otherwise, <c>false</c>.</returns> private bool IsAllowedAttribute(KeyValuePair <string, string> attribute) { return(AllowedAttributes.Contains(attribute.Key) // test html5 data- attributes || (AllowDataAttributes && attribute.Key != null && attribute.Key.StartsWith("data-", StringComparison.OrdinalIgnoreCase))); }
/// <summary> /// Determines whether the specified attribute is allowed. /// </summary> /// <param name="attribute">The attribute.</param> /// <returns><c>true</c> if the attribute is allowed; otherwise, <c>false</c>.</returns> private bool IsAllowedAttribute(IAttr attribute) { return(AllowedAttributes.Contains(attribute.Name) // test html5 data- attributes || (AllowDataAttributes && attribute.Name != null && attribute.Name.StartsWith("data-", StringComparison.OrdinalIgnoreCase))); }
private void ValidateAttributes(XElement element, SettingsFile origin) { if (AllowedAttributes != null) { if (!AllowedAttributes.Any() && element.HasAttributes) { throw new NuGetConfigurationException(string.Format(CultureInfo.CurrentCulture, Resources.UserSettings_UnableToParseConfigFile, string.Format(CultureInfo.CurrentCulture, Resources.NoAttributesAllowed, element.Name.LocalName, element.Attributes().Count()), origin.ConfigFilePath)); } foreach (var attribute in element.Attributes()) { if (!AllowedAttributes.Contains(attribute.Name.LocalName)) { throw new NuGetConfigurationException(string.Format(CultureInfo.CurrentCulture, Resources.UserSettings_UnableToParseConfigFile, string.Format(CultureInfo.CurrentCulture, Resources.AttributeNotAllowed, attribute.Name.LocalName, element.Name.LocalName), origin.ConfigFilePath)); } } } if (RequiredAttributes != null) { foreach (var requireAttribute in RequiredAttributes) { var attribute = element.Attribute(requireAttribute); if (attribute == null) { throw new NuGetConfigurationException(string.Format(CultureInfo.CurrentCulture, Resources.UserSettings_UnableToParseConfigFile, string.Format(CultureInfo.CurrentCulture, Resources.MissingRequiredAttribute, requireAttribute, element.Name.LocalName), origin.ConfigFilePath)); } } } if (AllowedValues != null) { foreach (var attributeValues in AllowedValues) { var attribute = element.Attribute(attributeValues.Key); if (attribute != null && !attributeValues.Value.Contains(attribute.Value.Trim())) { throw new NuGetConfigurationException(string.Format(CultureInfo.CurrentCulture, Resources.UserSettings_UnableToParseConfigFile, string.Format(CultureInfo.CurrentCulture, Resources.AttributeValueNotAllowed, attribute.Name.LocalName, attribute.Value.Trim(), element.Name.LocalName), origin.ConfigFilePath)); } } } if (DisallowedValues != null) { foreach (var attributeValues in DisallowedValues) { var attribute = element.Attribute(attributeValues.Key); if (attribute != null && attributeValues.Value.Contains(attribute.Value.Trim())) { throw new NuGetConfigurationException(string.Format(CultureInfo.CurrentCulture, Resources.UserSettings_UnableToParseConfigFile, string.Format(CultureInfo.CurrentCulture, Resources.AttributeValueNotAllowed, attribute.Name.LocalName, attribute.Value.Trim(), element.Name.LocalName), origin.ConfigFilePath)); } } } }