From 682fca8af9e811194b2e7a32bfe943e5a42a3c52 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Thu, 7 Dec 2023 13:03:10 +0100
Subject: [PATCH] fix output of commit message

---
 .../deployment/classes/project_gui.class.php  | 26 ++++++++++++++++---
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/public_html/deployment/classes/project_gui.class.php b/public_html/deployment/classes/project_gui.class.php
index 6d458ff1..73327cff 100644
--- a/public_html/deployment/classes/project_gui.class.php
+++ b/public_html/deployment/classes/project_gui.class.php
@@ -216,6 +216,24 @@ class projectgui extends project {
     }
 
 
+    /**
+     * fix output of commit message as html
+     * This is a compatibility function for older builds
+     * 
+     * @param  string  $sMessage  git commit message
+     * @return string
+     */
+    public function transformCommitMessage($sMessage){
+        if(strstr($sMessage, '<br>Author:')){
+            $_aReplace=[
+                '<br>Author:' => "\nAuthor:",
+                '<br>Date:' => "\nDate:",
+                '<br><br>' => "\n\n",
+            ];
+            $sMessage=str_replace(array_keys($_aReplace), array_values($_aReplace), $sMessage)." *";
+        }
+        return htmlentities($sMessage);
+    }
     /**
      * render html code for info link that shows popup with metadata on mouseover
      * @param array $aInfos   metainfos of the package (from json file)
@@ -245,7 +263,7 @@ class projectgui extends project {
                         . $this->_oHtml->getIconByType('revision') . t('revision') . ': ' . $this->_renderRevision($aInfos["revision"]) . '<br>'
                         . $this->_oHtml->getIconByType('comment') . t('commitmessage') . ': '
                         )
-                        . '<pre>' . strip_tags($aInfos["message"], '<br>') . '</pre>';
+                        . '<pre>' . $this->transformCommitMessage($aInfos["message"]) . '</pre>';
                 if (array_key_exists("more", $aOptions)) {
                     $sInfos.=$aOptions["more"];
                 }
@@ -511,12 +529,12 @@ class projectgui extends project {
                 // $sJsonUrl = $this->_getInfofile($sPhase, $sPlace);
                     $sReturn .=$this->_getChecksumDiv(
                         $aData["revision"], 
-                        $this->_oHtml->getIconByType('calendar') .' ' . date($sDateFormat, $oPkgDate)
+                        $this->_oHtml->getIconByType('calendar') .' ' . date($sDateFormat, $oPkgDate) . '<br>'
                         . $this->_oHtml->getIconByType('branch') . t('branch') . ': ' . $aData["branch"] . '<br>'
                         . $this->_oHtml->getIconByType('revision') . t('revision') . ': ' . $this->_renderRevision($aData["revision"]) . '<br>'
                         . $this->_oHtml->getIconByType('comment') . t('commitmessage') . ':<br>'
                     )
-                    . '<pre>' . strip_tags($aData["message"], '<br>') . '</pre>'
+                    . '<pre>' . $this->transformCommitMessage($aData["message"]) . '</pre>'
                 // . '<i class="glyphicon glyphicon-globe"></i> ' . t('url') . ': <a href="' . $sJsonUrl . '">' . $sJsonUrl . '</a><br>'
                 ;
                 if ($sPlace == "deployed" && array_key_exists("url", $this->_aPrjConfig["phases"][$sPhase])) {
@@ -1420,7 +1438,7 @@ class projectgui extends project {
                         . $this->_oHtml->getIconByType('revision') . t('revision') . ': ' . $this->_renderRevision($aRepodata["revision"]) . '<br>'
                         . $this->_oHtml->getIconByType('comment') . t('commitmessage') . ':<br>'
                         )
-                        ."<pre>" . strip_tags($aRepodata["message"], '<br>') . "</pre>";
+                        ."<pre>" . htmlentities($aRepodata["message"]). "</pre>";
                 } else {
                     $sReturn .= $this->_oHtml->getBox("error", sprintf(t('class-project-error-no-repoinfo'), $aRepodata["error"]))
                             . $this->renderLink("setup") . '<br>';
-- 
GitLab