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

Đang mở
#720 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

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

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

Từ ngày 13/11/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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.

Ngôn ngữ chính
Python
Star
15
Fork
11
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
464

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

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 intel/dokimi

Tất cả issue của intel/dokimi

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.