BUG: CharacterSpaceConverter introduces whitespace holes and trailing whitespace

Đang mở Phù hợp với người mới
#4,043 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@Kaap10 đang làm issue này rồi.

Từ ngày 7/11/2026.

  • #4044 của @Kaap10 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Tìm CharacterSpaceConverter và các bài kiểm thử của nó trong mã nguồn PyRIT. Đọc phần triển khai của bộ chuyển đổi và chạy các bài kiểm thử hiện có của bộ chuyển đổi trước; bổ sung kiểm thử cho dấu câu giữa các từ, dạng rút gọn và dấu câu ở cuối. Công việc hoàn tất khi dấu câu được xóa trước khi chèn khoảng trắng, đầu ra khớp với các ví dụ và mẫu dấu câu được biên dịch một lần ở cấp mô-đun.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Describe the bug

CharacterSpaceConverter spaces out characters with " ".join(prompt) before removing punctuation with re.sub(...). This order of operations introduces whitespace artifacts:

  1. Stripping punctuation leaves empty character "holes", producing 4 spaces between words (e.g., "Hello, world" -> "H e l l o w o r l d" instead of the standard 3-space inter-word spacing "H e l l o w o r l d").
  2. Contractions or mid-word punctuation leave double spaces (e.g., "How's" -> "H o w s" instead of "H o w s").
  3. Trailing punctuation leaves unwanted trailing whitespace (e.g., "hello!" -> "h e l l o ").

Additionally, the punctuation regex is recompiled on every invocation of convert_async rather than precompiled at module level.

Steps/Code to Reproduce
import asyncio
from pyrit.converter import CharacterSpaceConverter

async def main():
    converter = CharacterSpaceConverter()
    res1 = await converter.convert_async(prompt="hello!")
    print(repr(res1.output_text))  # prints 'h e l l o ' with trailing space

    res2 = await converter.convert_async(prompt="Hello, world! How's everything?")
    print(repr(res2.output_text))  # prints 'H e l l o    w o r l d    H o w  s   e v e r y t h i n g '

asyncio.run(main())
Expected Results

Punctuation should be stripped prior to character spacing so spacing remains uniform without artificial gaps or trailing whitespace:

  • "hello!" -> 'h e l l o'
  • "Hello, world! How's everything?" -> 'H e l l o w o r l d H o w s e v e r y t h i n g'
Actual Results
  • 'h e l l o '
  • 'H e l l o w o r l d H o w s e v e r y t h i n g '
Versions
  • OS: Windows 11
  • Python version: 3.12
  • PyRIT version: main
Ngôn ngữ chính
Python
Star
4.7k
Fork
1k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
510

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/PyRIT

Tất cả issue của microsoft/PyRIT

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.