fix(common): use lazy quantifiers in removeDynamicContent to avoid over-matching#6065
Open
ebrasha wants to merge 1 commit into
Open
fix(common): use lazy quantifiers in removeDynamicContent to avoid over-matching#6065ebrasha wants to merge 1 commit into
ebrasha wants to merge 1 commit into
Conversation
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.
What changed
removeDynamicContent()was using greedy.+between dynamic-marking anchors.On any page where the same prefix/suffix shows up more than once (SPAs, templated lists, repeated card components), that single greedy match would swallow everything from the first prefix to the last suffix and replace it with one collapsed block.
That over-cleanup hides real differences between True/False responses and feeds straight into false positives (and false negatives) downstream in the comparison logic.
I switched the two affected patterns from greedy to lazy:
^.+suffix→^.+?suffixfor the "suffix-only" case, so we stop at the first suffix instead of the lastprefix.+suffix→prefix.+?suffixfor the "both anchors" case, so each dynamic block gets cleaned individually instead of all of them merging into oneprefix.+$case stayed as-is — it's anchored at end-of-string, so greedy vs lazy doesn't change the result thereWhy this is better
The dynamic markings represent a single dynamic block, not a region spanning the entire page. Greedy was breaking that contract whenever the anchors repeated.
Some specifics worth calling out:
re.sub(which is global by default) actually walks the page and cleans each dynamic region one by one, which is what the markings were designed forfindDynamicContentbuilds the markings in the first placeScope
Only
lib/core/common.pyis touched.Change is limited to
removeDynamicContent()— two regex quantifiers and a docstring note.No public API changes, no behavior change on pages without repeating anchors.