A plain-UTF-8 text file with a .xlsx extension. python-xlsx must raise a typed InvalidFileException, not a bare zipfile.BadZipFile.
Library verdicts: python-xlsx: — xlsxjs: —
| Feature id | xlsx/malformed-non-zip |
|---|---|
| Format | xlsx |
| Category | malformed-recovery |
| Spec | ecma-376-5-part-2 § 10.1.1 Package |
No XPath assertions declared.
No render assertions declared.
scripts/gen_malformed_non_zip_xlsx.py
#!/usr/bin/env python3
"""Generate ``fixtures/xlsx/malformed-non-zip.xlsx``.
A plain-UTF-8 text file with a ``.xlsx`` extension. python-xlsx must
raise a typed ``InvalidFileException`` rather than a bare
``zipfile.BadZipFile``.
"""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from _malformed_common import write_plain_bytes
_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "xlsx" / "malformed-non-zip.xlsx"
_PAYLOAD = (
b"This file has a .xlsx extension but is plain UTF-8 text, not a "
b"ZIP archive. A conforming reader must reject it with a typed "
b"opc-level exception, not a bare zipfile.BadZipFile.\n"
) * 4
def main() -> int:
_OUT.parent.mkdir(parents=True, exist_ok=True)
write_plain_bytes(_OUT, _PAYLOAD)
print(_OUT)
return 0
if __name__ == "__main__":
raise SystemExit(main())
{
"id": "xlsx/malformed-non-zip",
"title": "Malformed input: file is not a ZIP archive",
"format": "xlsx",
"category": "malformed-recovery",
"summary": "A plain-UTF-8 text file with a .xlsx extension. python-xlsx must raise a typed InvalidFileException, not a bare zipfile.BadZipFile.",
"roles": [
"authoring"
],
"spec": {
"source": "ecma-376-5-part-2",
"clause": "10.1.1",
"element": "Package"
},
"fixtures": {
"machine": "xlsx/malformed-non-zip"
},
"generator": {
"python": "scripts/gen_malformed_non_zip_xlsx.py"
},
"behavior_assertions": [
{
"id": "raises-typed-exception",
"kind": "library_raises",
"library": "python-xlsx",
"method": "xlsx.load_workbook",
"args": [
"{fixture_path}"
],
"expected_exception": [
"InvalidFileException"
],
"forbidden_exception": "BadZipFile",
"description": "Must raise a typed InvalidFileException — NOT a bare zipfile.BadZipFile. python-xlsx wraps BadZipFile correctly today."
}
]
}
No rendered reference is available for this case.