Fix compute_head_fingerprint folding case-only title/meta changes#2036
Open
jichaowang02-lang wants to merge 1 commit into
Open
Conversation
compute_head_fingerprint lowercased the entire <head> (`head_html.lower()`) before extracting the title and meta values, so the captured signal values were lowercased too. Two heads that differ only in the case of a title or meta value (e.g. "iPhone" vs "IPHONE", "Buy Now" vs "BUY NOW") therefore hashed to the same fingerprint. CacheValidator treats an equal fingerprint as unchanged, so a genuinely updated page was reported FRESH and stale cached content was served. Match tags/attributes case-insensitively (re.IGNORECASE) against the original head instead, so the extracted values keep their original case. Tag/attribute case-insensitivity is preserved; identical content still hashes identically. Adds regression tests: a case-only value change now changes the fingerprint (fails on the old code), while tag/attribute-only case differences do not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
compute_head_fingerprintlowercases the entire<head>before extracting signals:So the captured values are lowercased, not just the tag/attribute matching. Two heads that differ only in the case of a title or meta value hash to the same fingerprint:
CacheValidatortreats an equal fingerprint as "unchanged", so a genuinely updated page is reported FRESH and stale cached content is served.Fix
Match tags/attributes case-insensitively with
re.IGNORECASEagainst the original head, so extracted values keep their case. Tag/attribute case-insensitivity is preserved (e.g.<TITLE>/META NAME=...CONTENT=still parse), and identical content still hashes identically.Testing
Adds two regression tests:
test_value_case_change_changes_fingerprint— a case-only value change now changes the fingerprint (fails on the current code).test_tag_and_attribute_case_does_not_change_fingerprint— markup-only case differences still yield the same fingerprint.