From 373bbd9fafa4b1f7c55bae2dbaf21a42c137c90d Mon Sep 17 00:00:00 2001 From: Ronald Tse Date: Fri, 9 Oct 2026 18:13:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20haraqat=20split=5Fplanes=20crashes=20on?= =?UTF-8?q?=20mark-only=20text=20(QCRI=20silver=20windows=20hit=20it);=20g?= =?UTF-8?q?uard=20returns=20empty=20planes=20=E2=80=94=20tests=20added?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- haraqat_planes.py | 6 +++++- test_haraqat_planes.py | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/haraqat_planes.py b/haraqat_planes.py index 30e1859..e6dcbe6 100644 --- a/haraqat_planes.py +++ b/haraqat_planes.py @@ -55,7 +55,11 @@ def split_planes(text: str) -> tuple[str, list[str]]: else: leading += pending if leading: - labels[0] = "".join(leading) + "\x00" + labels[0] + if labels: + labels[0] = "".join(leading) + "\x00" + labels[0] + else: + # mark-only text (no base letters): nothing to diacritize + return "", [] return "".join(skeleton), labels diff --git a/test_haraqat_planes.py b/test_haraqat_planes.py index 98ae4a0..233470b 100644 --- a/test_haraqat_planes.py +++ b/test_haraqat_planes.py @@ -1,3 +1,4 @@ +import haraqat_planes """Tests for the haraqat plane decomposition (Stoicheia WO, run-017). A diacritized Arabic string factors into two aligned planes: @@ -81,3 +82,26 @@ def test_sadeed_outputs_roundtrip(self): if __name__ == "__main__": unittest.main() + + +def test_split_planes_mark_only_text_returns_empty(): + """QCRI silver windows can be pure combining marks — must not crash.""" + assert haraqat_planes.split_planes("\u064e\u064b\u064f") == ("", []) + assert haraqat_planes.split_planes("\u0651\u0652") == ("", []) + + +def test_split_planes_leading_marks_ride_first_letter(): + skel, labels = haraqat_planes.split_planes("\u0651\u0628") + assert skel == "\u0628" + assert labels[0].startswith("\u0651") + +def test_split_planes_mark_only_text_returns_empty(): + """QCRI silver windows can be pure combining marks — must not crash.""" + assert haraqat_planes.split_planes("\u064e\u064b\u064f") == ("", []) + assert haraqat_planes.split_planes("\u0651\u0652") == ("", []) + + +def test_split_planes_leading_marks_ride_first_letter(): + skel, labels = haraqat_planes.split_planes("\u0651\u0628") + assert skel == "\u0628" + assert labels[0].startswith("\u0651")