Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

BUG TokenBijectionConverter cannot represent a literal hyphen, so "e-mail" encodes identically to "email" and decodes without the hyphen

已关闭
#3,128 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@kushaltalati 已经在做这个了。

开始于 2026年10月11日。

  • #3129 来自 @kushaltalati —— 未关闭

评估

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

调研方向

Start with pyrit/converter/bijection_converter.py and inspect TokenBijectionConverter's encoding, decoding pattern, and teaching instructions. Run the reproduction with the provided mapping, then check the converter tests under tests/unit/converter. Done means literal hyphens round-trip and e-mail encodes differently from email; the issue author says they already have a fix and regression tests ready to submit.

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

描述

Describe the bug

TokenBijectionConverter (pyrit/converter/bijection_converter.py) joins the code words of one plaintext word with - (_TOKEN_DELIMITER), and encode() passes every unmapped character through unchanged. A hyphen in the plaintext is therefore emitted as the same character as the delimiter, and lands between two code-word runs exactly where an inserted delimiter would. decode()'s pattern (\b(tok)(?:-(tok))*\b) consumes it as a delimiter, so the hyphen disappears:

plaintext encoded (mapping x -> xxx) decoded
email eee-mmm-aaa-iii-lll email
e-mail eee-mmm-aaa-iii-lll email
self-harm sss-eee-lll-fff-hhh-aaa-rrr-mmm selfharm

The class docstring says the delimiter is there "to keep them legible and unambiguously decodable", and the teaching instructions tell the target to "join adjacent code words with hyphens", which leaves the model no way to write a literal hyphen either. So the prompt sent to the target loses hyphens on the way in ("self-harm" becomes "selfharm" once decoded), and any hyphen in the target's answer is lost on the way back.

This is the same collision class that has already been fixed twice in this file: #2696 (literal apostrophes vs. _CASE_MARKER) and #2741 (literal digits vs. digit tokens) in DigitBijectionConverter. The hyphen case in TokenBijectionConverter was not covered.

Steps/Code to Reproduce
import string
from pyrit.converter import TokenBijectionConverter

mapping = {c: c * 3 for c in string.ascii_lowercase}  # explicit mapping, no tokenizer needed
conv = TokenBijectionConverter(tokenizer=None, mapping=mapping)
for text in ("e-mail", "email", "self-harm"):
    enc = conv.encode(prompt=text)
    print(text, "->", enc, "->", conv.decode(enc))
Expected Results

Each input round-trips, and e-mail does not encode to the same text as email.

e-mail -> eee--mmm-aaa-iii-lll -> e-mail
email -> eee-mmm-aaa-iii-lll -> email
self-harm -> sss-eee-lll-fff--hhh-aaa-rrr-mmm -> self-harm
Actual Results
e-mail -> eee-mmm-aaa-iii-lll -> email
email -> eee-mmm-aaa-iii-lll -> email
self-harm -> sss-eee-lll-fff-hhh-aaa-rrr-mmm -> selfharm

Hyphens that are not directly between two letters (a - b, -lead, trail-) happen to survive because the decode pattern requires a code word on both sides, so the loss is specific to hyphenated words, which is the common case.

Suggested fix

Escape a literal hyphen as a doubled delimiter (--) on encode, the same way DigitBijectionConverter doubles a literal apostrophe or tilde, and have the decode pattern match -- first and restore it to one hyphen. A doubled delimiter can never be produced by joining code words, so it is unambiguous. The teaching instructions should tell the target to write a literal hyphen as two hyphens.

I have the fix with regression tests ready and can open the PR. The new round-trip cases fail on main (6 failed) and pass with the change; tests/unit/converter passes in full.

Versions
  • OS: macOS 26.5
  • Python version: 3.14.8
  • PyRIT version: 1.2.0.dev0, installed from main (0a5abbf9) in editable mode
主要语言
Python
星标
4.6k
派生
944
平均合并
2 天 20 小时
30 天内合并 PR
309

环境准备

在 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 摘要。