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 <noreply@anthropic.com>
This commit is contained in:
dgtlmoonandClaude Opus 5.5 committed 2026-10-13 12:33:05 +02:00
1 parent 3e8de9eb52
commit 42bbc02c9e
2 files changed
+1 -38

No files matched your search

+1 -7
View File
@@ -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
@@ -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 = '<html><body>hello</body></html>'
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 = '<html><body><embed type="application/pdf"></body></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