From fd2919d562c13984d74f3b578bfdd1917acf0408 Mon Sep 17 00:00:00 2001
From: Carsten  Rose <carsten.rose@math.uzh.ch>
Date: Thu, 8 Mar 2018 16:05:32 +0100
Subject: [PATCH] Bug #5640 / UTF8 encoded strings: MAX LENGTH wrong

---
 extension/qfq/qfq/AbstractBuildForm.php | 2 +-
 extension/qfq/qfq/report/Report.php     | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/extension/qfq/qfq/AbstractBuildForm.php b/extension/qfq/qfq/AbstractBuildForm.php
index 35154dd51..acd4174fc 100644
--- a/extension/qfq/qfq/AbstractBuildForm.php
+++ b/extension/qfq/qfq/AbstractBuildForm.php
@@ -1102,7 +1102,7 @@ abstract class AbstractBuildForm {
 
         if ($formElement[FE_MAX_LENGTH] > 0 && $value !== '') {
             // crop string only if it's not empty (substr returns false on empty strings)
-            $value = substr($value, 0, $formElement[FE_MAX_LENGTH]);
+            $value = mb_substr($value, 0, $formElement[FE_MAX_LENGTH]);
         }
         // 'maxLength' needs an upper 'L': naming convention for DB tables!
         if ($formElement[FE_MAX_LENGTH] > 0) {
diff --git a/extension/qfq/qfq/report/Report.php b/extension/qfq/qfq/report/Report.php
index 5aa4aee69..2483a5bf1 100644
--- a/extension/qfq/qfq/report/Report.php
+++ b/extension/qfq/qfq/report/Report.php
@@ -620,7 +620,6 @@ class Report {
                 $assoc[REPORT_TOKEN_FINAL_VALUE . $keyAssoc] = $renderedColumn;
             }
 
-
             if ($flagOutput) {
                 //prints
                 $content .= $this->variables->doVariables($fsep);
@@ -659,10 +658,16 @@ class Report {
         $flagOutput = true;
         $dummy = false;
 
-        // Empty column names are allowed: check with isset
+        // Special column name:  '_...'? Empty column names are allowed: check with isset
         if (isset($columnName[0]) && $columnName[0] === TOKEN_COLUMN_CTRL) {
             $flagControl = true;
             $columnName = substr($columnName, 1);
+
+            // Special column name and hide output: '__...'? (double '_' at the beginning)
+            if (isset($columnName[0]) && $columnName[0] === TOKEN_COLUMN_CTRL) {
+                $flagOutput = false;
+                $columnName = substr($columnName, 1);
+            }
         }
 
         //TODO: reserved names,not starting with '_' will be still accepted - stop this!
-- 
GitLab