From 42bbc02c9efc3aba8dfc1114bf3a83dfc85cb3e7 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Tue, 13 Oct 2026 12:33:05 +0200 Subject: [PATCH] Revert the raw_content document checksum change Choosing between .content and .raw_content belongs in the general binary content handling (#1334), which will be done separately. The browser PDF test and the early "PDF not available" check stay. Co-Authored-By: Claude Opus 5.5 --- changedetectionio/processors/base.py | 8 +---- .../tests/unit/test_raw_document_checksum.py | 31 ------------------- 2 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 changedetectionio/tests/unit/test_raw_document_checksum.py diff --git a/changedetectionio/processors/base.py b/changedetectionio/processors/base.py index 96f8be256..e7730e28a 100644 --- a/changedetectionio/processors/base.py +++ b/changedetectionio/processors/base.py @@ -411,13 +411,7 @@ class difference_detection_processor(): def get_raw_document_checksum(self): checksum = None - # PDF only - checksum the PDF document itself, .content may not represent it (in a browser - # fetcher it can be the PDF viewer's HTML wrapper, the same for every version of the document). - # Everything else keeps using .content - raw_content = self.fetcher.raw_content - if isinstance(raw_content, bytes) and b'%PDF' in raw_content[:1024]: - checksum = hashlib.md5(raw_content).hexdigest() - elif self.fetcher.content: + if self.fetcher.content: checksum = hashlib.md5(self.fetcher.content.encode('utf-8')).hexdigest() return checksum diff --git a/changedetectionio/tests/unit/test_raw_document_checksum.py b/changedetectionio/tests/unit/test_raw_document_checksum.py deleted file mode 100644 index bc9711cb1..000000000 --- a/changedetectionio/tests/unit/test_raw_document_checksum.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python3 - -import hashlib -from types import SimpleNamespace - -from changedetectionio.processors.base import difference_detection_processor - - -def _checksum(content, raw_content): - processor = object.__new__(difference_detection_processor) - processor.fetcher = SimpleNamespace(content=content, raw_content=raw_content) - return processor.get_raw_document_checksum() - - -def test_html_uses_content(): - # requests sets raw_content for every page, but non-PDF checksums must stay on .content - html = 'hello' - assert _checksum(html, html.encode('utf-8') + b'\n') == hashlib.md5(html.encode('utf-8')).hexdigest() - assert _checksum(html, None) == hashlib.md5(html.encode('utf-8')).hexdigest() - - -def test_pdf_uses_raw_content(): - pdf = b'%PDF-1.4\nsome pdf body' - viewer_html = '' - # The browser's PDF viewer HTML is the same for every version, the PDF bytes are what count - assert _checksum(viewer_html, pdf) == hashlib.md5(pdf).hexdigest() - assert _checksum(viewer_html, pdf) != _checksum(viewer_html, pdf + b'changed') - - -def test_nothing_fetched(): - assert _checksum(None, None) is None