fix(telegram): hard-cut when fence body cut lands on the prefix
A leading space in the fenced body made the soft cut land at min_code_pos and re-emit the same fence forever. Require progress past the fence line.
This commit is contained in:
@@ -102,7 +102,7 @@ def _split_telegram_markdown(content: str, max_len: int) -> list[str]:
|
||||
adjusted = recut.rfind("\n", min_code_pos)
|
||||
if adjusted < min_code_pos:
|
||||
adjusted = recut.rfind(" ", min_code_pos)
|
||||
pos = adjusted if adjusted >= min_code_pos else budget
|
||||
pos = adjusted if adjusted > min_code_pos else budget
|
||||
elif pos + len(closing) > max_len:
|
||||
budget = max_len - len(closing)
|
||||
if budget <= min_code_pos:
|
||||
@@ -113,7 +113,11 @@ def _split_telegram_markdown(content: str, max_len: int) -> list[str]:
|
||||
adjusted = recut.rfind("\n", min_code_pos)
|
||||
if adjusted < min_code_pos:
|
||||
adjusted = recut.rfind(" ", min_code_pos)
|
||||
pos = adjusted if adjusted >= min_code_pos else budget
|
||||
pos = adjusted if adjusted > min_code_pos else budget
|
||||
if pos <= min_code_pos:
|
||||
chunks.append(content[:max_len])
|
||||
content = content[max_len:].lstrip()
|
||||
continue
|
||||
chunks.append(content[:pos] + closing)
|
||||
remainder = content[pos:]
|
||||
if remainder.startswith("\n"):
|
||||
|
||||
@@ -293,6 +293,19 @@ def test_split_telegram_markdown_tiny_limit_with_early_body_newline() -> None:
|
||||
assert plain.count("a") >= 100
|
||||
|
||||
|
||||
def test_split_telegram_markdown_leading_space_in_fence_body() -> None:
|
||||
body = "a" * 4500
|
||||
content = f"```\n {body}"
|
||||
|
||||
chunks = _split_telegram_markdown(content, TELEGRAM_MAX_MESSAGE_LEN)
|
||||
|
||||
assert chunks
|
||||
assert all(len(chunk) <= TELEGRAM_MAX_MESSAGE_LEN for chunk in chunks)
|
||||
plain = "".join(chunks).replace("```", "").replace("\n", "")
|
||||
assert plain.count("a") == 4500
|
||||
|
||||
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_creates_separate_pools_with_proxy(monkeypatch) -> None:
|
||||
|
||||
Reference in New Issue
Block a user