[BUG] Segment.split_cells doesn't handle zero width charachters correctly

オープン
#4,264 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
cli

調査の方向性

Start with Segment.split_cells and the cell-width helpers in rich/segment.py, then read split_text in rich/cells.py to see how it cuts text by cell position. Write a test like the one in the issue, using repr checks on the two halves of a Hebrew string with combining marks, and run it to see the current split. Done means the marks stay attached to their base characters and the existing cell-splitting tests still pass; the proposed split_text swap needs checking against them.

索引モデルが issue の本文から書いたものです。

説明

Needs triage

Describe the bug

Segment.split_cells() mishandles zero-width characters (such as Hebrew diacritical marks) when splitting text across cell boundaries, resulting in malformed segments where zero-width combining marks are incorrectly detached or split from their base characters.

Minimal reproduction / Unit Test

def test_split_cells_zero_width():
    hebrew_segment = Segment("שָׁלוֹם")
    left, right = hebrew_segment.split_cells(3)

    assert repr(left) == "Segment('שָׁלוֹ')"
    assert repr(right) == "Segment('ם')"

Proposed Fix
cells.py already has a function called split_text that can be used to solve the problem as such:

    def _split_cells(cls, segment: "Segment", cut: int) -> tuple["Segment", "Segment"]:
        """Split a segment in to two at a given cell position.

        Note that splitting a double-width character, may result in that character turning
        into two spaces.

        Args:
            segment (Segment): A segment to split.
            cut (int): A cell position to cut on.

        Returns:
            A tuple of two segments.
        """
        text, style, control = segment
        _Segment = Segment
        cell_length = segment.cell_length
        if cut >= cell_length:
            return segment, _Segment("", style, control)

        before, after = split_text(text, cut)
        return (
            _Segment(before, style, control),
            _Segment(after, style, control),
        )

I tried to publish it but wasn't able to since the repository limints pull requests t collaborators only.

主要言語
Python
スター
57.8k
フォーク
2.6k
平均マージ
20分
マージ済み PR(30日)
3

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Textualize/rich のほかの issue

Textualize/rich の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。