From a8f0d76654723749ad9ff59ef4b1aa4a50f6746d Mon Sep 17 00:00:00 2001 From: Pol Torrent i Soler Date: Thu, 28 Sep 2023 20:02:47 +0200 Subject: [PATCH] fix: restore chars in files that have beed wrongly converted to utf8 --- quizzes/lib/HList.class.php | 18 ++--- quizzes/lib/Hash.class.php | 12 ++-- quizzes/lib/IntHash.class.php | 12 ++-- .../quizzes/impl/ActionCommands.class.php | 72 ++++++++++++++++++- .../wiris/quizzes/impl/HTMLTools.class.php | 71 ++++++++++++------ 5 files changed, 141 insertions(+), 44 deletions(-) diff --git a/quizzes/lib/HList.class.php b/quizzes/lib/HList.class.php index 5c14a98b..402155dc 100644 --- a/quizzes/lib/HList.class.php +++ b/quizzes/lib/HList.class.php @@ -138,26 +138,26 @@ public function add($item) { public function __call($m, $a) { if(isset($this->$m) && is_callable($this->$m)) return call_user_func_array($this->$m, $a); - else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m])) - return call_user_func_array($this->»dynamics[$m], $a); + else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m])) + return call_user_func_array($this->»dynamics[$m], $a); else if('toString' == $m) return $this->__toString(); else - throw new HException('Unable to call «'.$m.'»'); + throw new HException('Unable to call «'.$m.'»'); } function __toString() { return $this->toString(); } } -function HList_0(&$»this) { - if($»this->q === null) { +function HList_0(&$»this) { + if($»this->q === null) { return null; } else { - return $»this->q[0]; + return $»this->q[0]; } } -function HList_1(&$»this) { - if($»this->h === null) { +function HList_1(&$»this) { + if($»this->h === null) { return null; } else { - return $»this->h[0]; + return $»this->h[0]; } } diff --git a/quizzes/lib/Hash.class.php b/quizzes/lib/Hash.class.php index 6c992daa..060c2322 100644 --- a/quizzes/lib/Hash.class.php +++ b/quizzes/lib/Hash.class.php @@ -13,9 +13,9 @@ public function getIterator() { public function toString() { $s = "{"; $it = $this->keys(); - $»it = $it; - while($»it->hasNext()) { - $i = $»it->next(); + $»it = $it; + while($»it->hasNext()) { + $i = $»it->next(); $s .= $i; $s .= " => "; $s .= Std::string($this->get($i)); @@ -56,12 +56,12 @@ public function set($key, $value) { public function __call($m, $a) { if(isset($this->$m) && is_callable($this->$m)) return call_user_func_array($this->$m, $a); - else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m])) - return call_user_func_array($this->»dynamics[$m], $a); + else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m])) + return call_user_func_array($this->»dynamics[$m], $a); else if('toString' == $m) return $this->__toString(); else - throw new HException('Unable to call »'.$m.'»'); + throw new HException('Unable to call »'.$m.'»'); } function __toString() { return $this->toString(); } } diff --git a/quizzes/lib/IntHash.class.php b/quizzes/lib/IntHash.class.php index 808f8fc9..c613e5fc 100644 --- a/quizzes/lib/IntHash.class.php +++ b/quizzes/lib/IntHash.class.php @@ -12,9 +12,9 @@ public function getIterator() { public function toString() { $s = "{"; $it = $this->keys(); - $»it = $it; - while($»it->hasNext()) { - $i = $»it->next(); + $»it = $it; + while($»it->hasNext()) { + $i = $»it->next(); $s .= _hx_string_rec($i, ""); $s .= " => "; $s .= Std::string($this->get($i)); @@ -55,12 +55,12 @@ public function set($key, $value) { public function __call($m, $a) { if(isset($this->$m) && is_callable($this->$m)) return call_user_func_array($this->$m, $a); - else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m])) - return call_user_func_array($this->»dynamics[$m], $a); + else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m])) + return call_user_func_array($this->»dynamics[$m], $a); else if('toString' == $m) return $this->__toString(); else - throw new HException('Unable to call «'.$m.'»'); + throw new HException('Unable to call «'.$m.'»'); } function __toString() { return $this->toString(); } } diff --git a/quizzes/lib/com/wiris/quizzes/impl/ActionCommands.class.php b/quizzes/lib/com/wiris/quizzes/impl/ActionCommands.class.php index d7ffbd13..7c847422 100644 --- a/quizzes/lib/com/wiris/quizzes/impl/ActionCommands.class.php +++ b/quizzes/lib/com/wiris/quizzes/impl/ActionCommands.class.php @@ -5,4 +5,74 @@ public function __construct(){} static $COMMANDS; function __toString() { return 'com.wiris.quizzes.impl.ActionCommands'; } } -com_wiris_quizzes_impl_ActionCommands::$COMMANDS = new _hx_array(array("avalua", "vurdere", "bewerten", "αξιολογώ", "evaluate", "evalúa", "évaluer", "valutare", "evaluere", "avalie")); +com_wiris_quizzes_impl_ActionCommands::$COMMANDS = new _hx_array(array("avalua", "vurdere", "bewerten", com_wiris_quizzes_impl_ActionCommands_0() . com_wiris_quizzes_impl_ActionCommands_1() . com_wiris_quizzes_impl_ActionCommands_2() . com_wiris_quizzes_impl_ActionCommands_3() . com_wiris_quizzes_impl_ActionCommands_4() . com_wiris_quizzes_impl_ActionCommands_5() . com_wiris_quizzes_impl_ActionCommands_6() . com_wiris_quizzes_impl_ActionCommands_7(), "evaluate", "eval" . com_wiris_quizzes_impl_ActionCommands_8() . "a", com_wiris_quizzes_impl_ActionCommands_9() . "valuer", "valutare", "evaluere", "avalie")); +function com_wiris_quizzes_impl_ActionCommands_0() { + { + $s = new haxe_Utf8(null); + $s->addChar(945); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_ActionCommands_1() { + { + $s = new haxe_Utf8(null); + $s->addChar(958); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_ActionCommands_2() { + { + $s = new haxe_Utf8(null); + $s->addChar(953); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_ActionCommands_3() { + { + $s = new haxe_Utf8(null); + $s->addChar(959); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_ActionCommands_4() { + { + $s = new haxe_Utf8(null); + $s->addChar(955); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_ActionCommands_5() { + { + $s = new haxe_Utf8(null); + $s->addChar(959); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_ActionCommands_6() { + { + $s = new haxe_Utf8(null); + $s->addChar(947); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_ActionCommands_7() { + { + $s = new haxe_Utf8(null); + $s->addChar(974); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_ActionCommands_8() { + { + $s = new haxe_Utf8(null); + $s->addChar(250); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_ActionCommands_9() { + { + $s = new haxe_Utf8(null); + $s->addChar(233); + return $s->toString(); + } +} diff --git a/quizzes/lib/com/wiris/quizzes/impl/HTMLTools.class.php b/quizzes/lib/com/wiris/quizzes/impl/HTMLTools.class.php index 9490003d..fa37fd1e 100644 --- a/quizzes/lib/com/wiris/quizzes/impl/HTMLTools.class.php +++ b/quizzes/lib/com/wiris/quizzes/impl/HTMLTools.class.php @@ -1673,20 +1673,16 @@ public function expandVariablesText($text, $textvariables) { return $this->replaceVariablesInsideHTML($text, $textvariables, com_wiris_quizzes_impl_MathContent::$TYPE_TEXT, false); } public function encodeMathML($html) { - $opentag = "«"; - $closetag = "»"; - $quote = "¨"; - $amp = "§"; $start = null; $end = 0; while(($start = _hx_index_of($html, "", $closetag, $formula); - $formula = str_replace("\"", $quote, $formula); - $formula = str_replace("&", $amp, $formula); + $formula = str_replace("<", com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_LT, $formula); + $formula = str_replace(">", com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_GT, $formula); + $formula = str_replace("\"", com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_QUOT, $formula); + $formula = str_replace("&", com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_AMP, $formula); $html = _hx_substr($html, 0, $start) . $formula . _hx_substr($html, $end, null); $end = $start + strlen($formula); unset($formula,$closemath); @@ -1694,21 +1690,17 @@ public function encodeMathML($html) { return $html; } public function decodeMathML($html) { - $opentag = "«"; - $closetag = "»"; - $quote = "¨"; - $amp = "§"; - $closemath = $opentag . "/math" . $closetag; + $closemath = com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_LT . "/math" . com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_GT; $start = null; $end = 0; - while(($start = _hx_index_of($html, $opentag . "math", $end)) !== -1) { + while(($start = _hx_index_of($html, com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_LT . "math", $end)) !== -1) { $end = _hx_index_of($html, $closemath, $start) + strlen($closemath); $formula = _hx_substr($html, $start, $end - $start); $formula = com_wiris_util_xml_WXmlUtils::htmlUnescape($formula); - $formula = str_replace($opentag, "<", $formula); - $formula = str_replace($closetag, ">", $formula); - $formula = str_replace($quote, "\"", $formula); - $formula = str_replace($amp, "&", $formula); + $formula = str_replace(com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_LT, "<", $formula); + $formula = str_replace(com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_GT, ">", $formula); + $formula = str_replace(com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_QUOT, "\"", $formula); + $formula = str_replace(com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_AMP, "&", $formula); $html = _hx_substr($html, 0, $start) . $formula . _hx_substr($html, $end, null); $end = $start + strlen($formula); unset($formula); @@ -1716,8 +1708,7 @@ public function decodeMathML($html) { return $html; } public function isMathMLEncoded($html) { - $opentag = "«"; - return _hx_index_of($html, $opentag . "math", null) !== -1; + return _hx_index_of($html, com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_LT . "math", null) !== -1; } public function extractVariableNames($html) { if($this->isMathMLEncoded($html)) { @@ -1947,6 +1938,10 @@ static function insertStringInSortedArray($s, $a) { } } } + static $SAFE_MATHML_LT; + static $SAFE_MATHML_GT; + static $SAFE_MATHML_QUOT; + static $SAFE_MATHML_AMP; static function encodeUnicodeChars($mathml) { $sb = new StringBuf(); $i = null; @@ -2051,6 +2046,10 @@ static function getEmptyCalcMeSession() { function __toString() { return 'com.wiris.quizzes.impl.HTMLTools'; } } com_wiris_quizzes_impl_HTMLTools::$EMPTY_CALCME_SESSION = "\x0A" . " \x0A" . " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\x0A" . " <mtext></mtext>\x0A" . " </math>\x0A" . " \x0A" . " \x0A" . " \x0A" . " \x0A" . " \x0A" . " \x0A" . " \x0A" . " \x0A" . " \x0A" . " \x0A" . ""; +com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_LT = com_wiris_quizzes_impl_HTMLTools_21(); +com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_GT = com_wiris_quizzes_impl_HTMLTools_22(); +com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_QUOT = com_wiris_quizzes_impl_HTMLTools_23(); +com_wiris_quizzes_impl_HTMLTools::$SAFE_MATHML_AMP = com_wiris_quizzes_impl_HTMLTools_24(); function com_wiris_quizzes_impl_HTMLTools_0(&$»this, &$_g, &$_g1, &$a, &$answer, &$answers, &$compound, &$h, &$i, &$i1, &$s) { if($»this->isMathMLString($s)) { return com_wiris_quizzes_impl_MathContent::$TYPE_MATHML; @@ -2061,7 +2060,7 @@ function com_wiris_quizzes_impl_HTMLTools_0(&$»this, &$_g, &$_g1, &$a, &$answer function com_wiris_quizzes_impl_HTMLTools_1(&$»this, &$close, &$e, &$i, &$it, &$n, &$open, &$sb, &$separators) { { $s = new haxe_Utf8(null); - $s->addChar(haxe_Utf8::charCodeAt($separators, com_wiris_quizzes_impl_HTMLTools_21($close, $e, $i, $it, $n, $open, $s, $sb, $separators))); + $s->addChar(haxe_Utf8::charCodeAt($separators, com_wiris_quizzes_impl_HTMLTools_25($close, $e, $i, $it, $n, $open, $s, $sb, $separators))); return $s->toString(); } } @@ -2194,7 +2193,35 @@ function com_wiris_quizzes_impl_HTMLTools_20(&$centerBaseline, &$crossOriginEnab return $proxyUrl . "?service=render&"; } } -function com_wiris_quizzes_impl_HTMLTools_21(&$close, &$e, &$i, &$it, &$n, &$open, &$s, &$sb, &$separators) { +function com_wiris_quizzes_impl_HTMLTools_21() { + { + $s = new haxe_Utf8(null); + $s->addChar(171); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_HTMLTools_22() { + { + $s = new haxe_Utf8(null); + $s->addChar(187); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_HTMLTools_23() { + { + $s = new haxe_Utf8(null); + $s->addChar(168); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_HTMLTools_24() { + { + $s = new haxe_Utf8(null); + $s->addChar(167); + return $s->toString(); + } +} +function com_wiris_quizzes_impl_HTMLTools_25(&$close, &$e, &$i, &$it, &$n, &$open, &$s, &$sb, &$separators) { if($i < $n) { return $i; } else {