From 497b46f113966672c2c5994bb376e25a3544a932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Mummert?= Date: Thu, 25 Dec 2025 15:01:20 +0100 Subject: [PATCH] Bugfix --- src/Service/PdfIndexService.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Service/PdfIndexService.php b/src/Service/PdfIndexService.php index 19d12ff..9d6dd82 100644 --- a/src/Service/PdfIndexService.php +++ b/src/Service/PdfIndexService.php @@ -84,12 +84,24 @@ class PdfIndexService * ===================================================== */ private function normalizePdfUrl(string $url): ?string { - $url = html_entity_decode($url); + // Fall 1: direkter /files/-Pfad + if (str_starts_with($url, '/files/') && str_ends_with($url, '.pdf')) { + return $url; + } - // direkter /files/*.pdf-Link - $path = parse_url($url, PHP_URL_PATH); - if ($path && preg_match('~^/files/.*\.pdf$~i', $path)) { - return $path; + // Fall 2: Contao-Download-Link mit ?p= + $decoded = html_entity_decode($url); + + $parts = parse_url($decoded); + if (!isset($parts['query'])) { + return null; + } + + parse_str($parts['query'], $query); + + if (!empty($query['p'])) { + // Contao speichert Pfade relativ zu /files + return '/files/' . ltrim($query['p'], '/'); } return null;