Digests of parsed JSON with ensure_ascii=False raise UnicodeEncodeError for a lone-surrogate escape in the input

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

メンテナーはふだん 1 日以内に返信

@antonwolfy がすでに取り組んでいます。

2026年11月13日 から。

評価

この issue はまだ評価されていません。

説明

Several digests dump parsed data with ensure_ascii=False and encode with .encode("utf-8"): item_digest and assignment_digest (dokimi/dokimi/eval/leakgate.py:162,175), graph_digest (dokimi/dokimi/eval_coverage.py:71), expectations_digest (dokimi/dokimi/repos/conformance.py:108), response_cache_key (dokimi/dokimi/caching.py:377) and _content_key (dokimi/dokimi/harnesses/harbor_export.py:100, resolved.encode()). A JSON or YAML escape such as "\udcff" in the input file loads as a lone surrogate and the encode raises. Plain file text is not a trigger: it is decoded as strict UTF-8.

Repro, each with json.loads('"n\\udcff"') as the value:

leakgate.item_digest({"grading": {"expected": S}}) -> UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 14: surrogates not allowed
eval_coverage.graph_digest({"nodes": [{"id": "a", "text": S, "path_class": "x"}]}) -> ... position 65
conformance.expectations_digest({"a": S}) -> ... position 7
caching.response_cache_key(litellm_model="m", messages=[{"role": "user", "content": S}]) -> ... position 41
harbor_export._content_key(path, "n\udcff") -> ... position 1

Fix options: .encode("utf-8", "surrogatepass") keeps every digest that encodes today unchanged and separates different surrogates; or refuse a lone surrogate in the loader with a message. Not errors="replace", which makes two inputs collide. Whether _content_key is reached depends on _task_toml writing a raw surrogate, which was not traced.

Found while fixing #675. The fix's PR is #721.

主要言語
Python
スター
15
フォーク
11
平均マージ
1日 9時間
マージ済み PR(30日)
464

環境構築

はじめの一歩

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

intel/dokimi のほかの issue

intel/dokimi の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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