aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Entry.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2022-09-05 13:13:07 +0200
committerGravatar GitHub <noreply@github.com> 2022-09-05 13:13:07 +0200
commit3b81708c1aa7dc0be9fbd017a85a57855094b57d (patch)
treea9028870c6de31153ed3bca1bc6276b5de55cfc1 /app/Models/Entry.php
parent442019a0548d3f1d888419930d38f1986e5cd773 (diff)
API protection limit content size (#4583)
* API protection limit content size We had no limit to the length of an article sent through our GReader API to clients, which was a problem: The article https://devblogs.microsoft.com/dotnet/performance_improvements_in_net_7/ from the feed https://devblogs.microsoft.com/dotnet/feed/ is about 700KB long, which makes some clients (tested with News+) fail. We should try other clients to verify that 500KB is a safe enough limit. * Light optimisation * Use class constant
Diffstat (limited to 'app/Models/Entry.php')
-rw-r--r--app/Models/Entry.php9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index feb094347..12cef68a5 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -652,6 +652,12 @@ class FreshRSS_Entry extends Minz_Model {
}
/**
+ * Some clients (tested with News+) would fail if sending too long item content
+ * @var int
+ */
+ const API_MAX_COMPAT_CONTENT_LENGTH = 500000;
+
+ /**
* N.B.: To avoid expensive lookups, ensure to set `$entry->_feed($feed)` before calling this function.
* N.B.: You might have to populate `$entry->_tags()` prior to calling this function.
* @param string $mode Set to `'compat'` to use an alternative Unicode representation for problematic HTML special characters not decoded by some clients;
@@ -690,6 +696,9 @@ class FreshRSS_Entry extends Minz_Model {
if ($mode === 'compat') {
$item['title'] = escapeToUnicodeAlternative($this->title(), false);
unset($item['alternate'][0]['type']);
+ if (mb_strlen($this->content(), 'UTF-8') > self::API_MAX_COMPAT_CONTENT_LENGTH) {
+ $item['summary']['content'] = mb_strcut($this->content(), 0, self::API_MAX_COMPAT_CONTENT_LENGTH, 'UTF-8');
+ }
} elseif ($mode === 'freshrss') {
$item['guid'] = $this->guid();
unset($item['summary']);