return $this->
sanitizeWithContext( W3CReference::CONTEXTS_MAP
[StringSanitizer::
htmlLower($element)] ?? W3CReference::CONTEXT_BODY,
$input );
} private function sanitizeWithContext(string
$context, string
$input): string
{ // Text context: early return with HTML encoding
if (W3CReference::CONTEXT_TEXT ===
$context) { return StringSanitizer::
encodeHtmlEntities($input);
} // Other context: build a DOM visitor
$this->domVisitors
[$context] ??=
$this->
createDomVisitorForContext($context);
// Prevent DOS attack induced by extremely long HTML strings
if (\
strlen($input) >
$this->config->
getMaxInputLength()) { $input =
substr($input, 0,
$this->config->
getMaxInputLength());
} // Only operate on valid UTF-8 strings. This is necessary to prevent cross