Check whether a variable is safe in context

@param  DOMNode $node  Context node
@param  Tag     $tag   Source tag
@param  string  $qname Name of the variable
@return void
774305
protected function checkVariable(DOMNode $node, $tag, $qname)
	{
		// Test whether this variable comes from a previous xsl:param or xsl:variable element
		$this->checkVariableDeclaration($node, $tag, 'xsl:param[@name="' . $qname . '"]');
		$this->checkVariableDeclaration($node, $tag, 'xsl:variable[@name="' . $qname . '"]');
	}
172298
public function visit($query, $node, string $context)
    {
        if ($node instanceof $this->node) {
            $child0 = $node->getChildByIndex(0);
            $child1 = $node->getChildByIndex(1);

            if ($context === Nodes\OrNode::class) {
                $query->orWhere($this->parseNode($query, $child0), $this->operator, $this->parseNode($query, $child1));
            }

            if ($context === Nodes\AndNode::class) {
                $query->where($this->parseNode($query, $child0), $this->operator, $this->parseNode($query, $child1));
            }
        }
    }
1081682
public function isClassTaggedWith($className, $tag)
    {
        if ($this->initialized === false) {
            return false;
        }
        if (!isset($this->reflectedClassNames[$className])) {
            $this->reflectClass($className);
        }
        if (!isset($this->classTagsValues[$className])) {
            return false;
        }
        return isset($this->classTagsValues[$className][$tag]);
    }
1230089
protected function getNodeValueByTagNameNS(DOMElement $node, $namespace, $tagName)
    {
        $results = $node->getElementsByTagNameNS($namespace, $tagName);
        for ($i = 0; $i < $results->length; $i++) {
            $result = $results->item($i);
            if (is_null($result->nodeValue)) {
                continue;
            }

            return $result->nodeValue;
        }

        return false;
    }
1311389
private static function isVariableDeclaration(Node $n, string $name)
    {
        if (
            // TODO - clean this up
            ($n instanceof Node\Expression\AssignmentExpression && $n->operator->kind === PhpParser\TokenKind::EqualsToken)
            && $n->leftOperand instanceof Node\Expression\Variable && $n->leftOperand->getName() === $name
        ) {
            return true;
        }

        if (
            ($n instanceof Node\ForeachValue || $n instanceof Node\ForeachKey)
            && $n->expression instanceof Node\Expression\Variable
            && $n->expression->getName() === $name
        ) {
            return true;
        }

        return false;
    }
124620
function(name, nodes) {
          if (name !== 'declaration') {
            return false;
          }

          if (
              nodes.content[0] &&
              nodes.content[0].content &&
              nodes.content[0].content[0] &&
              nodes.content[0].content[0].type &&
              nodes.content[0].content[0].type === 'variable'
            ) {
            return true;
          }

        }
1040277
public function assertElementNonVisibility($tag, $text) {
    $element = $this->getSession()->getPage();
    /** @var \Behat\Mink\Element\NodeElement[] $nodes */
    $nodes = $element->findAll('css', $tag);
    foreach ($nodes as $node) {
      if ($node->getText() === $text) {
        $this->assertElementNotVisible($text, $node);
      }
    }
  }
1290528
protected function isValidTag(string $tag, Message $message = null): void
    {
        $allowedTag = $this->getAllowedTag();
        if (!\in_array($tag, $allowedTag, true)) {
            throw new InvalidKeyException(sprintf(
                'tag must be either "%s".',
                implode(', ', $allowedTag)
            ));
        }

        if ($tag === SendInterface::TAG_ISSUE_RESOLUTION && $message !== null && !$message instanceof GenericTemplate) {
            throw new InvalidClassException(sprintf(
                'message must be an instance of %s if tag is set to %s.',
                GenericTemplate::class,
                SendInterface::TAG_ISSUE_RESOLUTION
            ));
        }
    }
1049513
protected function tagIsAllowed($tagName)
	{
		$n = $this->tagsConfig[$tagName]['bitNumber'];

		return (bool) ($this->context['allowed'][$n >> 3] & (1 << ($n & 7)));
	}
1301655
private function _retrieveNodeText(DOMNode $node, &$text)
    {
        if ($node->nodeType == XML_TEXT_NODE) {
            $text .= $node->nodeValue;
            if(!in_array($node->parentNode->tagName, $this->_inlineTags)) {
                $text .= ' ';
            }
        } else if ($node->nodeType == XML_ELEMENT_NODE  &&  $node->nodeName != 'script') {
            foreach ($node->childNodes as $childNode) {
                $this->_retrieveNodeText($childNode, $text);
            }
        }
    }
312050
public function filter($node, $tagname)
    {
        $ret = array();
        while ($node = Dom::getNextSiblingElement($node)) {
            array_push($ret, $node);
        }
        return $ret;
    }
25280
protected function getNodeValuesByTagName(DOMElement $node, $tagName)
    {
        $values = array();
        $results = $node->getElementsByTagName($tagName);
        if ($results->length) {
            foreach ($results as $result) {
                if ($result->nodeValue) {
                    $values[] = $result->nodeValue;
                }
            }
        }

        return $values;
    }
796325
public function begin_tag($tag, $attributes = null) {
        // TODO: chek the tag name is valid
        $pre = $this->level ? "\n" . str_repeat(' ', $this->level * 2) : ''; // Indent
        $tag = $this->casefolding ? strtoupper($tag) : $tag; // Follow casefolding
        $end = $this->nullcontent ? ' /' : ''; // Tag without content, close it

        // Build attributes output
        $attrstring = '';
        if (!empty($attributes) && is_array($attributes)) {
            // TODO: check the attr name is valid
            foreach ($attributes as $name => $value) {
                $name = $this->casefolding ? strtoupper($name) : $name; // Follow casefolding
                $attrstring .= ' ' . $name . '="'.
                    $this->xml_safe_attr_content($value) . '"';
            }
        }

        // Optional xml schema definition (level 0 only)
        $schemastring = '';
        if ($this->level == 0 && !empty($this->xmlschema)) {
            $schemastring .= "\n    " . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
                             "\n    " . 'xsi:noNamespaceSchemaLocation="' . $this->xml_safe_attr_content($this->xmlschema) . '"';
        }

        // Send to xml_output
        $this->write($pre . '<' . $tag . $attrstring . $schemastring . $end . '>');

        // Acumulate the tag and inc level
        if (!$this->nullcontent) {
            array_push($this->opentags, $tag);
            $this->level++;
        }
        $this->lastwastext = false;
    }
51071
private function loadTag(\DOMXPath $xpath, \DOMNode $node)
    {
        $tag = [
            'name' => null,
            'priority' => null,
            'attributes' => [],
        ];

        foreach ($node->attributes as $key => $attr) {
            if (in_array($key, ['name', 'priority'])) {
                $tag[$key] = $attr->value;
            } else {
                $tag['attributes'][$key] = $attr->value;
            }
        }

        return $tag;
    }
676822
protected function checkExpression(DOMNode $node, $expr, Tag $tag)
	{
		$this->checkContext($node);

		if (preg_match('/^\\$(\\w+)$/', $expr, $m))
		{
			// Either this expression came from a variable that is considered safe, or it's a
			// stylesheet parameters, which are considered safe by default
			$this->checkVariable($node, $tag, $m[1]);
		}
		elseif (preg_match('/^@[-\\w]+(?:\\s*\\|\\s*@[-\\w]+)*$/', $expr))
		{
			$this->checkAttributeExpression($node, $tag, $expr);
		}
		elseif (!$this->isExpressionSafe($expr))
		{
			throw new UnsafeTemplateException("Cannot assess the safety of expression '" . $expr . "'", $node);
		}
	}
143822
public function aliasElement($elName, $tagName)
	{
		$elName = $this->normalizeElementName($elName);

		$this->aliases[$elName][''] = TagName::normalize($tagName);
	}
244388
public function isSelfClosingTag($tagName)
    {
        return in_array($tagName, self::$SELF_CLOSING_TAGS, true) || (boolean)$this->fusionValue('selfClosingTag');
    }