Skip to content

Commit dbfd5b7

Browse files
cliffhallclaude
andcommitted
fix(fetch): match !important in any case and leave nested furniture hidden
Copilot review on #5308: lowercase a style value before stripping !important, and skip hidden candidates inside navigation or other page furniture, not only furniture that is itself hidden. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 3bddaec commit dbfd5b7

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎src/fetch/src/mcp_server_fetch/server.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ def _readability_content(html: str, use_readability_js: bool) -> str:
188188
def _hiding_declaration(declaration: str) -> bool:
189189
"""Whether one inline-style declaration is one Readability.js treats as hidden."""
190190
prop, _, value = declaration.partition(":")
191-
value = value.replace("!important", "").strip().lower()
191+
# Lowercased first: CSS keywords, `!important` included, ignore case.
192+
value = value.lower().replace("!important", "").strip()
192193
return (prop.strip().lower(), value) in {
193194
("display", "none"),
194195
("visibility", "hidden"),
@@ -240,7 +241,9 @@ def _recover_hidden_content(html: str, content: str) -> str:
240241
# Outermost only: unhiding a container exposes what it holds, and
241242
# anything hidden inside it stays hidden.
242243
if not any(_is_hidden(parent) for parent in tag.parents)
244+
# Furniture, or anything inside it (`<nav><div hidden>`), stays hidden.
243245
and not _is_page_chrome(tag)
246+
and not any(_is_page_chrome(parent) for parent in tag.parents)
244247
and _text_length(tag) > extracted
245248
]
246249
if not larger:

‎src/fetch/tests/test_hidden_ssr.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ async def fetch(web: FakeWeb, page: str, **serve_kwargs: Any) -> str:
9090
'style="position:absolute;top:-9999px;display:none"',
9191
"hidden",
9292
'style="display: NONE !important"',
93+
'style="display:none !IMPORTANT"',
9394
],
9495
)
9596
async def test_hidden_ssr_content_is_recovered(
@@ -129,7 +130,12 @@ async def test_page_with_small_hidden_element_is_extracted_once(
129130
@pytest.mark.usefixtures("node_readability")
130131
@pytest.mark.parametrize(
131132
("opening", "closing"),
132-
[("<nav hidden>", "</nav>"), ('<div role="navigation" hidden>', "</div>")],
133+
[
134+
("<nav hidden>", "</nav>"),
135+
('<div role="navigation" hidden>', "</div>"),
136+
("<nav><div hidden>", "</div></nav>"),
137+
('<header><div style="display:none">', "</div></header>"),
138+
],
133139
)
134140
async def test_hidden_navigation_is_left_hidden(
135141
web: FakeWeb, calls: list[str], opening: str, closing: str
@@ -195,6 +201,7 @@ async def test_no_readability_js_is_never_rerun(web: FakeWeb, calls: list[str])
195201
('<div style="display:none">', True),
196202
('<div style="color: red; Display : None ;">', True),
197203
('<div style="visibility:hidden !important">', True),
204+
('<div style="visibility:hidden !Important">', True),
198205
("<div hidden>", True),
199206
('<div aria-hidden="true">', True),
200207
("<div>", False),

0 commit comments

Comments
 (0)