BUG: CharacterSpaceConverter introduces whitespace holes and trailing whitespace

未关闭 适合新手
#4,043 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@Kaap10 已经在做这个了。

开始于 2026年11月7日。

  • #4044 来自 @Kaap10 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

在 PyRIT 源代码中找到 CharacterSpaceConverter 及其测试。阅读转换器的实现,并先运行现有的转换器测试;为单词之间的标点、缩写形式和末尾标点添加测试覆盖。完成标准是:在插入空格之前移除标点,输出与示例一致,并且标点模式在模块级别只编译一次。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Python
星标
4.7k
派生
1k
平均合并
2 天 4 小时
30 天内合并 PR
510

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/PyRIT 的其他 Issue

查看 microsoft/PyRIT 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。