"""Unit tests for :func:`lightrag.utils.strip_control_characters`. The helper removes C0 control / separator characters (notably the ``\\x1c``-``\\x1f`` FS/GS/RS/US separators) and Unicode surrogates while preserving ``\\t``/``\\n``/``\\r`` and *not* touching markup or surrounding whitespace. It is the cleaner injected at the parse-result persist points so parser-extracted body text cannot carry these chars into chunks/storage. """ import pytest from lightrag.utils import strip_control_characters pytestmark = pytest.mark.offline def test_removes_fs_gs_rs_us_separators(): raw = "a\x1cb\x1dc\x1ed\x1fe" assert strip_control_characters(raw) == "abcde" def test_removes_other_c0_and_del(): # NUL, BS, VT, FF, SO..US range members, and DEL. raw = "x\x00\x08\x0b\x0c\x0e\x1f\x7fy" assert strip_control_characters(raw) == "xy" def test_preserves_tab_newline_carriage_return(): raw = "line1\tcol\nline2\r\nline3" # The whitespace control chars survive verbatim. assert strip_control_characters(raw) == raw def test_noop_for_clean_text_returns_unchanged(): clean = " 普通文本 with