Follow up to https://www.drupal.org/project/drupal/issues/3562543#comment-16769882

\Drupal\file\EventSubscriber\FileEventSubscriber::coerceToValidUtf8 (assuming that lands) and very similar code in \Drupal\Component\Transliteration\PhpTransliteration::transliterate should be refactored to a public static in \Drupal\Component\Utility\Unicode

Note: the newer implementation in coerceToValidUtf8() has advantages over the hash approach in transliterate() - likely we'd want to use the former here.

Comments

mcdruid created an issue. See original summary.

mcdruid’s picture

Issue summary: View changes
longwave’s picture

Instead of the hash approach to replace unknown characters, mbstring provides a function - sample code:

    $codepoint = mb_ord($unknown_character, 'UTF-8');
    if ($codepoint === FALSE) {
      throw new \InvalidArgumentException('$unknown_character must be a single valid UTF-8 character.');
    }

    $previous = mb_substitute_character();
    mb_substitute_character($codepoint);
    $string = mb_convert_encoding($string, 'UTF-8', 'UTF-8');
    mb_substitute_character($previous);
    return $string;