Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
fix: degrade malformed document resource URLs
myhloliff6972f13a2c
diff --git a/mineru/model/flash/epub/package.py b/mineru/model/flash/epub/package.pyindex 3a4a80cf..334c7d5c 100644--- a/mineru/model/flash/epub/package.py+++ b/mineru/model/flash/epub/package.py@@ -277,7 +277,10 @@ class EpubPackage:raw_href = (href or "").strip()if not raw_href:return None- split = urlsplit(raw_href)+ try:+ split = urlsplit(raw_href)+ except ValueError:+ return Noneif split.scheme or split.netloc:return Noneraw_path = split.pathdiff --git a/mineru/model/flash/epub/xhtml.py b/mineru/model/flash/epub/xhtml.pyindex 8e2bf2e3..1b10950a 100644--- a/mineru/model/flash/epub/xhtml.py+++ b/mineru/model/flash/epub/xhtml.py@@ -342,7 +342,10 @@ class EpubAnchorRegistry:normalized = (href or "").strip()if not normalized or any(ord(char) < 32 for char in normalized) or any(char in normalized for char in ("<", ">")):return None- split = urlsplit(normalized)+ try:+ split = urlsplit(normalized)+ except ValueError:+ return Noneif split.scheme or split.netloc or normalized.startswith(("//", "\\")):return Nonetarget = self._package.resolve_reference(normalized, base_part=base_part)@@ -355,7 +358,10 @@ class EpubAnchorRegistry:normalized = (href or "").strip()if not normalized or any(ord(char) < 32 for char in normalized) or any(char in normalized for char in ("<", ">")):return None- split = urlsplit(normalized)+ try:+ split = urlsplit(normalized)+ except ValueError:+ return Noneif split.scheme:if split.scheme.casefold() not in _SAFE_EXTERNAL_SCHEMES:return Nonediff --git a/mineru/model/flash/office/odf/package.py b/mineru/model/flash/office/odf/package.pyindex 256ee425..07823f29 100644--- a/mineru/model/flash/office/odf/package.py+++ b/mineru/model/flash/office/odf/package.py@@ -225,7 +225,10 @@ class OdfPackage:normalized_href = unquote((href or "").strip())if not normalized_href or normalized_href.startswith("#"):return None- split = urlsplit(normalized_href)+ try:+ split = urlsplit(normalized_href)+ except ValueError:+ return Noneif split.scheme or split.netloc:return Nonecandidate = split.path.replace("\\", "/")diff --git a/tests/unittest/test_flash_epub.py b/tests/unittest/test_flash_epub.pyindex 52c33e9e..881f9392 100644--- a/tests/unittest/test_flash_epub.py+++ b/tests/unittest/test_flash_epub.py@@ -464,6 +464,31 @@ def test_epub_corrupt_chapter_keeps_empty_spine_placeholder() -> None:assert "SVG text" in middle.pages[2].blocks[0].content # type: ignore[union-attr]+def test_epub_malformed_resource_and_link_references_degrade_locally() -> None:+ """验证非法 URI 只丢弃样式、图片或链接目标,不阻断章节正文。"""+ package = EpubPackage(build_epub_fixture())+ chapter_path = "EPUB/text/ch1.xhtml"+ try:+ root = package.xml_part(chapter_path, allow_external_doctype=True)+ assert root is not None+ stylesheet = next(element for element in root.iter() if etree.QName(element).localname == "link")+ hyperlink = next(element for element in root.iter() if etree.QName(element).localname == "a")+ image = next(element for element in root.iter() if etree.QName(element).localname == "img")+ stylesheet.set("href", "http://[")+ hyperlink.set("href", "http://[")+ image.set("src", "http://[")++ anchors = build_anchor_registry([(chapter_path, root)], package)+ blocks = EpubChapterConverter(package, chapter_path, root, anchors).convert()++ assert "Chapter One" in str(blocks)+ assert "chapter two" in str(blocks)+ assert "Remote image" in str(blocks)+ assert "<hyperlink>chapter two" not in str(blocks)+ finally:+ package.close()++def test_epub_rejects_encrypted_unsafe_and_dtd_inputs() -> None:"""验证选中正文加密、上跳成员和 DTD 在语义解析前稳定失败。"""encrypted = build_epub_fixture(encrypted_paths=("EPUB/text/ch1.xhtml",))diff --git a/tests/unittest/test_flash_odf.py b/tests/unittest/test_flash_odf.pyindex a2ea6e27..4f0d0a17 100644--- a/tests/unittest/test_flash_odf.py+++ b/tests/unittest/test_flash_odf.py@@ -585,6 +585,22 @@ def test_odf_corrupt_optional_styles_and_external_image_degrade_locally() -> Nonassert pages == [[{"type": BlockType.TEXT, "content": "visible"}]]+def test_odf_malformed_image_and_object_references_degrade_locally() -> None:+ """验证非法图片和对象 URI 仅丢弃资源,不阻断 ODF 正文。"""+ content = """<office:document-content+ xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"+ xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"+ xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"+ xmlns:xlink="http://www.w3.org/1999/xlink">+ <office:body><office:text><text:p>visible</text:p><draw:frame>+ <draw:object xlink:href="http://["/><draw:image xlink:href="http://["/>+ </draw:frame></office:text></office:body></office:document-content>"""++ pages = OdtModel().predict(BytesIO(build_odf_package("odt", content)))++ assert pages == [[{"type": BlockType.TEXT, "content": "visible"}]]++def test_odf_style_cycle_is_bounded_and_preserves_text() -> None:"""验证循环 parent-style-name 在有限链路内降级,不阻塞正文解析。"""content = """<office:document-content