exclude base64 data (#567)
This commit is contained in:
@@ -44,6 +44,15 @@ RESERVED_ATTRIBUTES = {
|
|||||||
"value",
|
"value",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BASE64_INCLUDE_ATTRIBUTES = {
|
||||||
|
"href",
|
||||||
|
"src",
|
||||||
|
"poster",
|
||||||
|
"srcset",
|
||||||
|
"icon",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ELEMENT_NODE_ATTRIBUTES = {
|
ELEMENT_NODE_ATTRIBUTES = {
|
||||||
"id",
|
"id",
|
||||||
}
|
}
|
||||||
@@ -474,6 +483,13 @@ def trim_element_tree(elements: list[dict]) -> list[dict]:
|
|||||||
if not queue_ele.get("interactable"):
|
if not queue_ele.get("interactable"):
|
||||||
del queue_ele["id"]
|
del queue_ele["id"]
|
||||||
|
|
||||||
|
if "attributes" in queue_ele:
|
||||||
|
new_attributes = _trimmed_base64_data(queue_ele["attributes"])
|
||||||
|
if new_attributes:
|
||||||
|
queue_ele["attributes"] = new_attributes
|
||||||
|
else:
|
||||||
|
del queue_ele["attributes"]
|
||||||
|
|
||||||
if "attributes" in queue_ele and not queue_ele.get("keepAllAttr", False):
|
if "attributes" in queue_ele and not queue_ele.get("keepAllAttr", False):
|
||||||
tag_name = queue_ele["tagName"] if "tagName" in queue_ele else ""
|
tag_name = queue_ele["tagName"] if "tagName" in queue_ele else ""
|
||||||
new_attributes = _trimmed_attributes(tag_name, queue_ele["attributes"])
|
new_attributes = _trimmed_attributes(tag_name, queue_ele["attributes"])
|
||||||
@@ -495,6 +511,17 @@ def trim_element_tree(elements: list[dict]) -> list[dict]:
|
|||||||
return elements
|
return elements
|
||||||
|
|
||||||
|
|
||||||
|
def _trimmed_base64_data(attributes: dict) -> dict:
|
||||||
|
new_attributes: dict = {}
|
||||||
|
|
||||||
|
for key in attributes:
|
||||||
|
if key in BASE64_INCLUDE_ATTRIBUTES and "data:" in attributes.get(key, ""):
|
||||||
|
continue
|
||||||
|
new_attributes[key] = attributes[key]
|
||||||
|
|
||||||
|
return new_attributes
|
||||||
|
|
||||||
|
|
||||||
def _trimmed_attributes(tag_name: str, attributes: dict) -> dict:
|
def _trimmed_attributes(tag_name: str, attributes: dict) -> dict:
|
||||||
new_attributes: dict = {}
|
new_attributes: dict = {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user