fix: prevent remove_overlay_elements from deleting html/body tags - #2164
fix: prevent remove_overlay_elements from deleting html/body tags#2164Battleplus wants to merge 2 commits into
Conversation
Resolves unclecode#2161 The remove_overlay_elements script could remove the entire page body when it matched common overlay selectors (e.g. class containing "popup"). Some popular WordPress themes (Bridge) add a class with "popup" to the body tag, causing the whole page to be stripped. Added tagName guards to both the high-z-index removal loop and the common-selectors removal loop so that html and body elements are never removed by the overlay cleanup logic.
Signed-off-by: Battleplus <3559424769@qq.com>
|
Follow-up audit found one remaining removal path: the final fixed/sticky-element pass could still delete a position-fixed body. The guard is now shared across all three passes and protects HTML, HEAD, and BODY. Added a browser regression test covering popup/modal classes, a fixed body, and removal of the real modal. Validation: node --check passed; pytest tests/browser/test_overlay_document_structure.py: 1 passed. Commit: ccc9003. |
|
Closing as a duplicate after the full audit. Earlier PR #2163 protects HTML, HEAD, and BODY in all three overlay-removal passes and includes two browser regressions for popup-class and position-fixed body cases. The follow-up here found and fixed the same final fixed/sticky pass, but #2163 is earlier and more comprehensive. |
这次改了什么
remove_overlay_elements脚本在清理弹窗/overlay 时,会误删<body>和<html>元素。原因是部分 WordPress 主题(如 Bridge)在<body>上添加了包含 "popup" 的 class,导致querySelectorAll('[class*="popup"]')匹配到 body 并将其移除,整个页面变空白。修法:在两处移除循环中添加
tagName守卫:两处都跳过
HTML和BODY标签。怎么验证的
test_remove_overlay_elements测试通过<body class="popup-overlay">页面,确认 body 不被移除风险
极低。只增加两个 tagName 检查,不影响任何现有 overlay 清理逻辑。html/body 本来就不应该被移除。
Closes #2161