From 0d3d410bd2efed3d9ed22b4e93959340c1eabae8 Mon Sep 17 00:00:00 2001 From: winchen Date: Fri, 31 Jul 2026 21:16:31 +0800 Subject: [PATCH] fix: parse native image media urls --- dist/api/messages.php | 8 ++++++-- public/api/messages.php | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dist/api/messages.php b/dist/api/messages.php index 0727371..a3feffe 100644 --- a/dist/api/messages.php +++ b/dist/api/messages.php @@ -627,7 +627,11 @@ function formatWebGroupMessage( function cleanupNativeMediaUrl(string $url): string { - return rtrim($url, " \t\r\n\0\x0B\"'<>.,;)]}"); + // WildFire's protobuf payload places the next field tag (0x40, "@") + // and a control byte immediately after remoteMediaUrl. Keep this helper + // defensive if it receives an unbounded match from older payloads. + $url = preg_replace('/[\x00-\x1F\x7F].*$/s', '', $url) ?? $url; + return rtrim($url, " \t\r\n\0\x0B\"'<>.,;)]}@"); } function nativeMediaUrlScore(string $url): int @@ -655,7 +659,7 @@ function extractNativeMediaUrlFromData($data): string if (!is_string($data) || $data === '') { return ''; } - if (!preg_match_all("~https?://[^\\s\"'<>\\x00]+~i", $data, $matches)) { + if (!preg_match_all("~https?://[^\\s\"'<>\\x00-\\x1F\\x7F]+~i", $data, $matches)) { return ''; } diff --git a/public/api/messages.php b/public/api/messages.php index 0727371..a3feffe 100644 --- a/public/api/messages.php +++ b/public/api/messages.php @@ -627,7 +627,11 @@ function formatWebGroupMessage( function cleanupNativeMediaUrl(string $url): string { - return rtrim($url, " \t\r\n\0\x0B\"'<>.,;)]}"); + // WildFire's protobuf payload places the next field tag (0x40, "@") + // and a control byte immediately after remoteMediaUrl. Keep this helper + // defensive if it receives an unbounded match from older payloads. + $url = preg_replace('/[\x00-\x1F\x7F].*$/s', '', $url) ?? $url; + return rtrim($url, " \t\r\n\0\x0B\"'<>.,;)]}@"); } function nativeMediaUrlScore(string $url): int @@ -655,7 +659,7 @@ function extractNativeMediaUrlFromData($data): string if (!is_string($data) || $data === '') { return ''; } - if (!preg_match_all("~https?://[^\\s\"'<>\\x00]+~i", $data, $matches)) { + if (!preg_match_all("~https?://[^\\s\"'<>\\x00-\\x1F\\x7F]+~i", $data, $matches)) { return ''; }