Test if the supplied attribute is allowed by this whitelist for this tag
@param tagName tag to consider allowing the attribute in
@param el element under test, to confirm protocol
@param attr attribute under test
@return true if allowed
164857
protected boolean isSafeAttribute(String tagName, Element el, Attribute attr) {
        TagName tag = TagName.valueOf(tagName);
        AttributeKey key = AttributeKey.valueOf(attr.getKey());

        Set<AttributeKey> okSet = attributes.get(tag);
        if (okSet != null && okSet.contains(key)) {
            if (protocols.containsKey(tag)) {
                Map<AttributeKey, Set<Protocol>> attrProts = protocols.get(tag);
                // ok if not defined protocol; otherwise test
                return !attrProts.containsKey(key) || testValidProtocol(el, attr, attrProts.get(key));
            } else { // attribute found, no protocols defined, so OK
                return true;
            }
        }
        // might be an enforced attribute?
        Map<AttributeKey, AttributeValue> enforcedSet = enforcedAttributes.get(tag);
        if (enforcedSet != null) {
            Attributes expect = getEnforcedAttributes(tagName);
            String attrKey = attr.getKey();
            if (expect.hasKeyIgnoreCase(attrKey)) {
                return expect.getIgnoreCase(attrKey).equals(attr.getValue());
            }
        }
        // no attributes defined for tag, try :all tag
        return !tagName.equals(":all") && isSafeAttribute(":all", el, attr);
    }
1167794
function isElementAllowed(element) {
  const allowed = ALLOWED_ELEMENTS[element.namespaceURI];
  if (!allowed) {
    return false;
  }

  return allowed.indexOf(element.tagName.toLowerCase()) !== -1;
}
981219
protected function checkAttributeNode(DOMAttr $attribute, Tag $tag)
	{
		// Parse the attribute value for XPath expressions and assess their safety
		foreach (AVTHelper::parse($attribute->value) as $token)
		{
			if ($token[0] === 'expression')
			{
				$this->checkExpression($attribute, $token[1], $tag);
			}
		}
	}
330002
static final String attr(Element element, String name, boolean ignoreNamespace) {
        NamedNodeMap attributes = element.getAttributes();

        for (int i = 0; i < attributes.getLength(); i++) {
            String localName = attributes.item(i).getNodeName();

            // [#103] If namespaces are ignored, consider only local
            // part of possibly namespace-unaware Element
            if (ignoreNamespace)
                localName = stripNamespace(localName);

            if (name.equals(localName))
                return attributes.item(i).getNodeValue();
        }

        return null;
    }
268758
public boolean addPreserveTag(final String tagName) {

        Vector<Attribute> attributeList = new Vector<Attribute>(1);
        Attribute tagNameAttribute = new Attribute();
        tagNameAttribute.setName(tagName.toLowerCase());
        attributeList.add(tagNameAttribute);
        Tag keepTag = m_nodeFactory.createTagNode(null, 0, 0, attributeList);
        boolean result = m_nodeFactory.addTagPreserve(keepTag);
        return result;
    }
330177
public void openTagSameLine(final QName tag,
                              final String attrName,
                              final String attrVal) throws IOException {
    lb();
    emitQName(tag);
    attribute(attrName, attrVal);
    endOpeningTag();
  }
507394
protected function elementHasAttribute(DomElement $element, $attributeName)
    {
        // First try to return for link
        if ($element->localName === 'link' && $element->hasAttribute($attributeName)) {
            return true;
        }

        // Second return for embed
        if ($element->hasAttribute(EmbedLinking::TEMP_PREFIX . $attributeName)) {
            return true;
        }

        return false;
    }
457785
public function createElement($tagName, array $attributes = array(), $value = "", $isClosable = true, $templateToBeRendered = 'html_element_template') {
        if($this->_element_factory instanceof ElementFactory) {
            return $this->_element_factory->generateElement($tagName, $attributes, $value, $isClosable, $templateToBeRendered);
        }

        return false;
    }
979254
public boolean toBoolean(Element el, String attributeName) {
	return Caster.toBooleanValue(el.getAttribute(attributeName), false);
    }
1336500
public static Boolean getAttributeBoolean(Tag tag, String attrName) throws EvaluatorException {
	Boolean b = getAttributeLiteral(tag, attrName).getBoolean(null);
	if (b == null) throw new EvaluatorException("attribute [" + attrName + "] must be a constant boolean value");
	return b;
    }
555200
def setting_attribute_is_allowed?(name, user)
            return false unless user.can_write?(self, name)
            (self.whitelisted_attributes && self.whitelisted_attributes.has_key?( name.to_sym)) ||
            (
              self.attribute_names.include?( name.to_s ) &&
              ( self.blacklisted_attributes.nil? ||
                ! self.blacklisted_attributes.has_key?( name.to_sym )  )
            )
        end
608800
function getElAttributes(tag,attr) {
        var obj, knownBooleans, attrs, attrName, attrVal;

        obj = {};

        // known boolean attributes
        // we can check for matching boolean properties, but older browsers
        // won't know about HTML5 boolean attributes that we still read from
        knownBooleans = ',' + 'autoplay,controls,loop,muted,default' + ',';

        if (tag && tag.attributes && tag.attributes.length > 0) {
            attrs = tag.attributes;

            for (var i = attrs.length - 1; i >= 0; i--) {
                attrName = attrs[i].name;
                attrVal = attrs[i].value;

                // check for known booleans
                // the matching element property will return a value for typeof
                if (typeof tag[attrName] === 'boolean' || knownBooleans.indexOf(',' + attrName + ',') !== -1) {
                    // the value of an included boolean attribute is typically an empty
                    // string ('') which would equal false if we just check for a false value.
                    // we also don't want support bad code like autoplay='false'
                    attrVal = (attrVal !== null) ? true : false;
                }

                if(attr && attrName == attr){
                    return attrVal;
                }

                obj[attrName] = attrVal;
            }
        }
        if(attr && typeof attr == 'string'){
            return tag[attr];
        }
        return obj;
    }
290547
def is_tag_matched(self, tag, **attribute_filter):
        
        if len(attribute_filter) <= 0:
            return True
        for attr, value in attribute_filter.items():
            # TODO: figure out if both android:name and name tag exist which one to give preference
            _value = tag.get(self._ns(attr))
            if _value is None:
                log.warning("Failed to get the attribute with namespace")
                _value = tag.get(attr)
            if _value != value:
                return False
        return True
503184
public function allowsElement($name)
    {
        if (!empty($this->currentNesting)) {
            $parent_token = array_pop($this->currentNesting);
            $this->currentNesting[] = $parent_token;
            $parent = $this->htmlDefinition->info[$parent_token->name];
        } else {
            $parent = $this->htmlDefinition->info_parent_def;
        }
        if (!isset($parent->child->elements[$name]) || isset($parent->excludes[$name])) {
            return false;
        }
        // check for exclusion
        for ($i = count($this->currentNesting) - 2; $i >= 0; $i--) {
            $node = $this->currentNesting[$i];
            $def  = $this->htmlDefinition->info[$node->name];
            if (isset($def->excludes[$name])) {
                return false;
            }
        }
        return true;
    }
1113778
public function check(DOMElement $template, Tag $tag)
	{
		$nodes = $template->getElementsByTagNameNS(self::XMLNS_XSL, 'copy-of');
		foreach ($nodes as $node)
		{
			$expr = $node->getAttribute('select');

			if (!preg_match('#^@[-\\w]*(?:\\s*\\|\\s*@[-\\w]*)*$#D', $expr))
			{
				throw new UnsafeTemplateException("Cannot assess the safety of '" . $node->nodeName . "' select expression '" . $expr . "'", $node);
			}
		}
	}
1236951
private function subtag_check ($tagName)
  {
    $propName = lcfirst ($tagName);
    if ($this->current instanceof Metadata) {
      switch ($this->current->type) {
        // All descendants of a metadata property are always metadata.
        case type::metadata:
          return true;
      }
      // Descendants of a content property are children, not properties.
      return false;
    }
    // If the current component defines an property with the same name as the tag being checked, and if that property
    // supports begin specified as a tag, the tag is a subtag.
    return $this->current->supportsProperties () && $this->current->props->defines ($propName, true);
  }
1153634
def validateTagAttributes(self, attribs, element):
		""""""
		out = {}
		if element not in _whitelist:
			return out
		whitelist = _whitelist[element]
		for attribute in attribs:
			value = attribs[attribute]
			if attribute not in whitelist:
				continue
			# Strip javascript "expression" from stylesheets.
			# http://msdn.microsoft.com/workshop/author/dhtml/overview/recalc.asp
			if attribute == u'style':
				value = self.checkCss(value)
				if value == False:
					continue
			elif attribute == u'id':
				value = self.escapeId(value)
			# If this attribute was previously set, override it.
			# Output should only have one attribute of each name.
			out[attribute] = value
		return out