fix: use .search() instead of .match() for negative patterns in PruningContentFilter#1808
Open
jnMetaCode wants to merge 1 commit intounclecode:mainfrom
Open
fix: use .search() instead of .match() for negative patterns in PruningContentFilter#1808jnMetaCode wants to merge 1 commit intounclecode:mainfrom
jnMetaCode wants to merge 1 commit intounclecode:mainfrom
Conversation
…ngContentFilter Signed-off-by: JiangNan <1394485448@qq.com>
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
PruningContentFilter._compute_class_id_weight()usesself.negative_patterns.match()(lines 771, 775) to check CSS classes and element IDs against negative patterns. However,re.match()only matches at the start of the string, so a class like"main sidebar-nav"would not be caught by a pattern intended to match"sidebar"or"nav".The base class
RelevantContentFilter.is_excluded()(line 327) correctly uses.search()for the sameself.negative_patternsregex. This fix aligns_compute_class_id_weightwith that behavior.Changes
content_filter_strategy.pyline 771:self.negative_patterns.match(classes)→self.negative_patterns.search(classes)content_filter_strategy.pyline 775:self.negative_patterns.match(element_id)→self.negative_patterns.search(element_id)Impact
Without this fix, negative patterns (e.g., sidebar, nav, footer) fail to penalize elements when the matching substring is not at the start of the class/id string, causing irrelevant content to score higher than it should.