} 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
// site scripting issues on Internet Explorer 6. Idea from Drupal (filter_xss).
if (!
$this->
isValidUtf8($input)) { return '';
}