@param string $html
@param array  $allowedTags
@param array  $allowedAttributes

@return string
185374
public function purify($html, $allowedTags = null, $allowedAttributes = null)
    {
        $html = (string)preg_replace('@<script.*>.*</script>@isU', '', $html);
        if ($html === '') {
            return '';
        }

        if (strpos($html, '<body>') === false) {
            $html = '<!doctype html><html><body>' . $html . '</body></html>';
        }

        $doc = new \DOMDocument();
        try {
            @$doc->loadHTML($html);
        } catch (\Exception $e) {
            return '';
        }

        $body = $doc->getElementsByTagName('body');
        if ($allowedTags !== null) {
            $tags = ',' . implode(',', $allowedTags) . ',';
        } else {
            $tags = $this->_allowedTags;
        }

        if ($allowedAttributes !== null) {
            $attributes = ',' . implode(',', $allowedAttributes) . ',';
        } else {
            $attributes = $this->_allowedAttributes;
        }

        $this->_purify(iterator_to_array($body->item(0)->childNodes), $tags, $attributes);
        $body = $doc->getElementsByTagName('body');
        return substr($doc->saveHTML($body->item(0)), 6, -7);
    }
453306
public function setAllowedHttpMethods(array $allowedHttpMethods = null)
    {
        $results = null;
        if (is_array($allowedHttpMethods)) {
            $results = array_map(function ($method) {
                $method = trim($method);
                $method = strtolower($method);

                return $method;
            }, $allowedHttpMethods);

            $results = array_combine($results, $results);
        }
        $this->allowedHttpMethods = $results;

        return $this;
    }
1289858
public function getHtml(array $attributes = []): string
    {
        if ($this->minimumValue !== null) {
            $attributes['min'] = $this->minimumValue;
        }

        if ($this->maximumValue !== null) {
            $attributes['max'] = $this->maximumValue;
        }

        return parent::getHtml($attributes);
    }
1154031
public static function html_tag_callback($matches)
    {
        // It might be an ending of a comment, ignore (#6464)
        if (substr($matches[3], -2) == '--') {
            $matches[0] = '';
            return implode('', $matches);
        }

        $tagname = $matches[2];
        $tagname = preg_replace(array(
            '/:.*$/',                // Microsoft's Smart Tags <st1:xxxx>
            '/[^a-z0-9_\[\]\!?-]/i', // forbidden characters
        ), '', $tagname);

        // fix invalid closing tags - remove any attributes (#1489446)
        if ($matches[1] == '</') {
            $matches[3] = '';
        }

        return $matches[1] . $tagname . $matches[3];
    }
1018265
protected function addAttributes(&$html, array $attributes)
	{
		if ( count($attributes) > 0 )
		{
			$attributes = Html::arrayToAttributes($attributes);

			$html .= ' ' . $attributes;
		}
	}
805690
public static function stripTagsDeep($arr, $allowTags = '') {
		if (is_array($arr)) {
			foreach ($arr as $key => $val) {
				$arr[$key] = stripTagsDeep($val, $allowTags);
			}
		} else {
			$arr = static::stripTags($arr, $allowTags);
		}

		return $arr;
	}
728112
public static function areValidHtmlAttributes($htmlAttributes)
    {
        /*
         * Not a string?
         * Nothing to do
         */
        if (!is_string($htmlAttributes)) {
            return false;
        }

        $pattern = self::getHtmlAttributePattern();

        return (bool)preg_match_all($pattern, $htmlAttributes);
    }
244160
private function parseAttributes(string $html): string
    {
        $remainingHtml = \mb_substr($html, mb_strlen($this->name) + 1);
        while (\mb_strpos($remainingHtml, '>') !== false && preg_match("/^\s*[\/]?>/", $remainingHtml) === 0) {
            $remainingHtml = $this->parseAttribute($remainingHtml);
        }

        return $remainingHtml;
    }
27842
private function getPurifier($allowedTags)
    {
        $sanitizer = $this->getDefaultPurifier();

        $sanitizer->set('HTML.Allowed', $allowedTags);

        /**
         * Define custom HTML Definition for mark tool
         */
        if ($def = $sanitizer->maybeGetRawHTMLDefinition()) {
            $def->addElement('mark', 'Inline', 'Inline', 'Common');
        }

        $purifier = new \HTMLPurifier($sanitizer);

        return $purifier;
    }
693955
static function htmlAttributes(array $attributes = array()) {
    foreach ($attributes as $attribute => &$data) {
      $data = implode(' ', (array) $data);
      $data = $attribute . '="' . self::checkPlain($data) . '"';
    }
    return $attributes ? ' ' . implode(' ', $attributes) : '';
  }
982908
function(allowedAttributes) {
    var tmp = []
    this.forEach(function(record) {
      tmp.push(record.toJson(allowedAttributes))
    })
    return tmp
  }
815326
private function removeUnprocessableTags($html)
    {
        if (empty($this->unprocessableHtmlTags)) {
            return $html;
        }

        $unprocessableHtmlTags = implode('|', $this->unprocessableHtmlTags);

        return preg_replace(
            '/<\\/?(' . $unprocessableHtmlTags . ')[^>]*>/i',
            '',
            $html
        );
    }
505320
public function asText(StringLength $length = null, array $allowedTags = [])
    {
        return $this->handleFilter(
                function() use($length, $allowedTags)
                {
                    $textFilter = new filter\TextFilter();
                    return filter\RangeFilter::wrap(
                            $textFilter->allowTags($allowedTags),
                            $length
                    );
                }
        );
    }
74039
public function addAttributes($attributes, $html = [])
    {
        if (!empty($attributes)) {
            foreach ($attributes as $key => $value) {
                if (!is_null($value)) {
                    $html[] = $key.'="'.Html::entities($value).'"';
                }
            }
        }

        return (count($html) > 0) ? ' '.implode(' ', $html) : '';
    }
610396
protected function renderXML(
        ServerRequestInterface $request,
        ResponseInterface $response,
        array $allowedMethods
    ) {
        $message = sprintf('Method %s is not allowed', $request->getMethod());
        $baseSep = str_repeat(' ', 4);
        $sep = str_repeat($baseSep, 2);
        $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
            . "<root>\n"
            . "{$baseSep}<error>\n"
            . "{$sep}<message>{$message}</message>\n";

        if ($this->isDisplayError()) {
            $method = htmlentities($request->getMethod());
            $allowedMethodXML = '';
            foreach ($allowedMethods as $value) {
                $value = htmlentities($value);
                $allowedMethodXML .= "{$baseSep}<method>{$value}</method>\n{$sep}";
            }

            $xml .= "{$sep}<request_method>{$method}</request_method>\n";
            $xml .= "{$sep}<allowed_methods>\n{$sep}{$allowedMethodXML}</allowed_methods>\n";
        }

        $xml .= "{$baseSep}</error>\n</root>";
        echo $xml;
    }
257504
private function prepareParametersUrl(array $params, array $allowedParams)
    {
        $allowedParams = array_flip($allowedParams);
        $params = array_intersect_key($params, $allowedParams);

        $paramsUrlItems = [];
        foreach ($params as $key => $param) {
            $paramsUrlItems[] = $key . '=' . urlencode($param);
        }

        $paramsUrl = join('&', $paramsUrlItems);
        if (strlen($paramsUrl) > 0) {
            $paramsUrl = '?' . $paramsUrl;
        }

        return $paramsUrl;
    }
1232030
public static function stripTags($data, $allow_tags = null)
    {
        if (\is_array($data)) {
            foreach ($data as $k => $v) {
                $data[$k] = self::stripTags($v, $allow_tags);
            }

            return $data;
        }

        if (\is_string($data) || is_numeric($data)) {
            return strip_tags($data, $allow_tags);
        }

        return false;
    }