From 43aa9cddc58b79d6af5b897333bfde18bb2deb75 Mon Sep 17 00:00:00 2001
From: Hypolite Petovan <hypolite@mrpetovan.com>
Date: Sat, 17 Dec 2022 21:13:24 -0500
Subject: [PATCH] Trim terms of service rules before turning them to an array

---
 src/Core/System.php | 4 ++--
 src/Module/Tos.php  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/Core/System.php b/src/Core/System.php
index 707649a49d..ec214fea9d 100644
--- a/src/Core/System.php
+++ b/src/Core/System.php
@@ -251,7 +251,7 @@ class System
 
 				// Don't show multiple calls from the Database classes to show the essential parts of the callstack
 				$func['database'] = in_array($func['class'], ['Friendica\Database\DBA', 'Friendica\Database\Database']);
-				if (!$previous['database'] || !$func['database']) {	
+				if (!$previous['database'] || !$func['database']) {
 					$classparts = explode("\\", $func['class']);
 					$callstack[] = array_pop($classparts).'::'.$func['function'];
 					$previous = $func;
@@ -678,7 +678,7 @@ class System
 			$html = BBCode::convert($rulelist, false, BBCode::EXTERNAL);
 
 			$msg = HTML::toPlaintext($html, 0, true);
-			foreach (explode("\n", $msg) as $line) {
+			foreach (explode("\n", trim($msg)) as $line) {
 				$line = trim($line);
 				if ($line) {
 					$rules[] = ['id' => (string)++$id, 'text' => $line];
diff --git a/src/Module/Tos.php b/src/Module/Tos.php
index 11cecac44d..6109a2470f 100644
--- a/src/Module/Tos.php
+++ b/src/Module/Tos.php
@@ -83,8 +83,8 @@ class Tos extends BaseModule
 
 		$tpl = Renderer::getMarkupTemplate('tos.tpl');
 		if ($this->config->get('system', 'tosdisplay')) {
-			$lines = $this->config->get('system', 'tosrules');
-			if (!empty($lines)) {
+			$lines = trim($this->config->get('system', 'tosrules') ?: '');
+			if ($lines) {
 				$rules = "[list=1]";
 				foreach (explode("\n", $lines) as $line) {
 					$rules .= "\n[*]" . $line;
-- 
2.39.5