Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  namespace OpenSpout\Common\Helper\Escaper;
   6  
   7  /**
   8   * @internal
   9   */
  10  final class ODS implements EscaperInterface
  11  {
  12      /**
  13       * Escapes the given string to make it compatible with XLSX.
  14       *
  15       * @param string $string The string to escape
  16       *
  17       * @return string The escaped string
  18       */
  19      public function escape(string $string): string
  20      {
  21          /*
  22           * 'ENT_DISALLOWED' ensures that invalid characters in the given document type are replaced.
  23           * Otherwise control characters like a vertical tab "\v" will make the XML document unreadable by the XML processor.
  24           *
  25           * @see https://github.com/box/spout/issues/329
  26           */
  27          return htmlspecialchars($string, ENT_QUOTES | ENT_DISALLOWED, 'UTF-8');
  28      }
  29  
  30      /**
  31       * Unescapes the given string to make it compatible with XLSX.
  32       *
  33       * @param string $string The string to unescape
  34       *
  35       * @return string The unescaped string
  36       */
  37      public function unescape(string $string): string
  38      {
  39          // ==============
  40          // =   WARNING  =
  41          // ==============
  42          // It is assumed that the given string has already had its XML entities decoded.
  43          // This is true if the string is coming from a DOMNode (as DOMNode already decode XML entities on creation).
  44          // Therefore there is no need to call "htmlspecialchars_decode()".
  45          return $string;
  46      }
  47  }