From b59526c59051ba6e26f8626136883b8cecaf131a Mon Sep 17 00:00:00 2001
From: Greg Sarjeant <1686767+gsarjeant@users.noreply.github.com>
Date: Mon, 16 Jun 2025 19:36:36 -0400
Subject: [PATCH] Clean up escaping, linking, and feeds.
---
src/Framework/Util/Util.php | 30 ++++++++++++++++++----------
src/View/HomeView/HomeView.php | 4 ++--
templates/feed/atom.php | 36 +++++++++++++++++++---------------
templates/feed/rss.php | 35 +++++++++++++++++++++------------
templates/partials/home.php | 4 ++--
templates/partials/tick.php | 2 +-
6 files changed, 67 insertions(+), 44 deletions(-)
diff --git a/src/Framework/Util/Util.php b/src/Framework/Util/Util.php
index 328e7d2..54af536 100644
--- a/src/Framework/Util/Util.php
+++ b/src/Framework/Util/Util.php
@@ -1,20 +1,30 @@
"\'()]+)~i',
- fn($matches) => '' . $matches[1] . '',
- $safe
- );
+ function($matches) use ($link_attrs) {
+ $escaped_url = rtrim($matches[1], '.,!?;:)]}>');
+ $clean_url = html_entity_decode($escaped_url, ENT_QUOTES, 'UTF-8');
- return $safe;
- }
+ return '' . $escaped_url . '';
+ },
+ $text
+ );
+ }
// For relative time display, compare the stored time to the current time
// and display it as "X seconds/minutes/hours/days etc." ago
diff --git a/src/View/HomeView/HomeView.php b/src/View/HomeView/HomeView.php
index ba29a11..da17826 100644
--- a/src/View/HomeView/HomeView.php
+++ b/src/View/HomeView/HomeView.php
@@ -8,8 +8,8 @@ class HomeView {
- = htmlspecialchars(Util::relative_time($tick['timestamp'])) ?>
- = Util::escape_and_linkify($tick['tick']) ?>
+ = Util::escape_html(Util::relative_time($tick['timestamp'])) ?>
+ = Util::linkify(Util::escape_html($tick['tick'])) ?>
diff --git a/templates/feed/atom.php b/templates/feed/atom.php
index 7ed1587..f85dfa6 100644
--- a/templates/feed/atom.php
+++ b/templates/feed/atom.php
@@ -1,45 +1,49 @@
siteTitle);
-$siteUrl = htmlspecialchars($config->baseUrl);
-$basePath = htmlspecialchars($config->basePath);
+$feedTitle = Util::escape_xml("$config->siteTitle Atom Feed");
+$siteUrl = Util::escape_xml($config->baseUrl . $config->basePath);
+$feedUrl = Util::escape_xml($config->baseUrl . $config->basePath . 'feed/atom');
$updated = date(DATE_ATOM, strtotime($ticks[0]['timestamp'] ?? 'now'));
header('Content-Type: application/atom+xml; charset=utf-8');
echo '' . "\n";
?>
- = "$siteTitle Atom Feed" ?>
+
-
- = $updated ?>
- = $siteUrl . $basePath ?>
+ title=""
+ href="" />
+
+
+
= $siteTitle ?>
- = $tickText ?>
+ = $tickTitle ?>
= $tickUrl ?>
= $tickTime ?>
- = $tickText ?>
+ = $tickContent ?>
diff --git a/templates/feed/rss.php b/templates/feed/rss.php
index d5484e2..294516d 100644
--- a/templates/feed/rss.php
+++ b/templates/feed/rss.php
@@ -4,34 +4,43 @@
// Need to have a little php here because the starting xml tag
// will mess up the PHP parser.
// TODO - I think short php tags can be disabled to prevent that.
+
header('Content-Type: application/rss+xml; charset=utf-8');
echo '' . "\n";
?>
- siteTitle, ENT_XML1, 'UTF-8') ?> RSS Feed
- baseUrl . $config->basePath, ENT_XML1, 'UTF-8')?>
-
- siteDescription, ENT_XML1, 'UTF-8') ?>
+ siteTitle . 'RSS Feed') ?>
+ baseUrl . $config->basePath)?>
+
+ siteDescription) ?>
en-us
baseUrl . $config->basePath . $tickPath;
+ // build the tick entry components
+ $tickPath = "tick/$year/$month/$day/$hour/$minute/$second";
+ $tickUrl = Util::escape_xml($config->baseUrl . $config->basePath . $tickPath);
+ $tickDate = date(DATE_RSS, strtotime($tick['timestamp']));
+ $tickTitle = Util::escape_xml($tick['tick']);
+ $tickDescription = Util::linkify($tickTitle);
?>
-
-
- baseUrl . $config->basePath . "tick/$tickPath", ENT_XML1, 'UTF-8'); ?>
-
-
-
+
+
+
+
+
diff --git a/templates/partials/home.php b/templates/partials/home.php
index 4c10bd8..64c674d 100644
--- a/templates/partials/home.php
+++ b/templates/partials/home.php
@@ -11,7 +11,7 @@
About: = $user->about ?>
website)): ?>
- Website: = Util::escape_and_linkify($user->website) ?>
+ Website: = Util::linkify(Util::escape_html($user->website)) ?>
mood) || Session::isLoggedIn()): ?>
@@ -27,7 +27,7 @@
diff --git a/templates/partials/tick.php b/templates/partials/tick.php
index 8ec7d21..97fccb0 100644
--- a/templates/partials/tick.php
+++ b/templates/partials/tick.php
@@ -2,4 +2,4 @@
Tick from = $tickTime->format('Y-m-d H:i:s'); ?>
-
= Util::escape_and_linkify($tick) ?>
+
= Util::linkify(Util::escape_html($tick)) ?>