From 6c24e867cfa915398d9fd272e7ea666dbdf1e6c8 Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Mon, 6 Dec 2021 17:21:22 +0100
Subject: [PATCH] fix handling of url and entity encoding for ExternModule,
 avoid usage of multibyte API, fixes #460

---
 lib/extern/lib/ExternElement.class.php |  6 +++---
 lib/extern/lib/ExternModule.class.php  | 30 +++++++-------------------
 2 files changed, 11 insertions(+), 25 deletions(-)

diff --git a/lib/extern/lib/ExternElement.class.php b/lib/extern/lib/ExternElement.class.php
index 90d496b20a5..5fa513b7249 100644
--- a/lib/extern/lib/ExternElement.class.php
+++ b/lib/extern/lib/ExternElement.class.php
@@ -472,7 +472,7 @@ class ExternElement {
         if ($this->config->getValue($args['main_module'], 'incdata')) {
             $link = $sri_link;
             if ($args['link_args']) {
-                if (mb_strrpos($link, '?')) {
+                if (strpos($link, '?')) {
                     $link .= '&' . $args['link_args'];
                 } else {
                     $link .= '?' . $args['link_args'];
@@ -494,7 +494,7 @@ class ExternElement {
                 }
                 $link .= 'page_url=' . $sri_link;
             } elseif ($extern_link) {
-                if (mb_strrpos($extern_link, '?')) {
+                if (strpos($extern_link, '?')) {
                     $link = "$extern_link&module=$module_name";
                 } else {
                     $link = "$extern_link?module=$module_name";
@@ -525,4 +525,4 @@ class ExternElement {
         }
         return ExternModule::ExtHtmlReady($link);
     }
-}
\ No newline at end of file
+}
diff --git a/lib/extern/lib/ExternModule.class.php b/lib/extern/lib/ExternModule.class.php
index 0151b70a121..0a7ddd5e2d9 100644
--- a/lib/extern/lib/ExternModule.class.php
+++ b/lib/extern/lib/ExternModule.class.php
@@ -460,9 +460,9 @@ class ExternModule {
         }
         $query_parts = [];
         if (is_array($params)) {
-            $param_key = 'ext_' . mb_strtolower($this->name);
+            $param_key = 'ext_' . strtolower($this->name);
             foreach ($params as $name => $value) {
-                $query_parts[] = "{$param_key}[{$name}]=" . $value;
+                $query_parts[] = "{$param_key}[{$name}]=" . urlencode($value);
             }
         }
 
@@ -501,7 +501,6 @@ class ExternModule {
             }
             if (is_array($config_meta_data)) {
                 $module = $config_meta_data['module_name'];
-            //  var_dump($this->config);
             } else {
                 return '';
             }
@@ -511,7 +510,7 @@ class ExternModule {
         if (is_array($query_parts) && count($query_parts)) {
             $url .= '&' . implode('&', $query_parts);
         }
-        return $url;
+        return self::ExtHtmlReady($url);
     }
 
     function getLinkToSelf ($params = null, $with_module_params = false, $linked_element_name = null) {
@@ -519,28 +518,15 @@ class ExternModule {
     }
 
     function getModuleParams ($params = null) {
-        $param_key = 'ext_' . mb_strtolower($this->name);
+        $param_key = 'ext_' . strtolower($this->name);
         if (is_array($_REQUEST[$param_key])) {
             $ret = [];
             if (is_null($params)) {
-                if (is_array($_GET[$param_key])) {
-                    foreach ($_GET[$param_key] as $key => $value) {
-                        $ret[$key] = urldecode($value);
-                    }
-                }
-                if (is_array($_POST[$param_key])) {
-                    foreach ($_POST[$param_key] as $key => $value) {
-                        $ret[$key] = $value;
-                    }
-                }
-                return $ret;
+                return $_REQUEST[$param_key];
             }
             foreach ($params as $param) {
-                if (isset($_GET[$param_key][$param])) {
-                    $ret[$param] = urldecode($_GET[$param_key][$param]);
-                }
-                if (isset($_POST[$param_key][$param])) {
-                    $ret[$param] = $_POST[$param_key][$param];
+                if (isset($_REQUEST[$param_key][$param])) {
+                    $ret[$param] = $_REQUEST[$param_key][$param];
                 }
             }
             return $ret;
@@ -585,4 +571,4 @@ class ExternModule {
         }
         return false;
     }
-}
\ No newline at end of file
+}
-- 
GitLab