Code review: binary paths containing ` b/` are truncated and misclassified as renames

Đang mở Phù hợp với người mới
#3,936 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 1 ngày

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

Từ ngày 24/11/2026.

  • #3969 của @Guihakka2 — đ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
74/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ệ
typescript
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu với parseDiffGitHeader trong packages/core/diff-paths.ts, nơi chứa regex cho diff --git a/... b/... không được đặt trong dấu ngoặc kép, sau đó theo dõi cách dùng nó trong parseDiffToFiles trong packages/core/diff-files.ts. Chạy đoạn bun repro-diff-path.ts của issue để xác nhận đầu ra sai của icon.png/oldPath, rồi thêm các test parser bên cạnh các test diff hiện có. Hoàn tất khi header nhị phân có đường dẫn bằng nhau cho ra path: "assets b/icon.png" mà không có oldPath và trạng thái modified, trong khi đường dẫn có dấu ngoặc kép và các trường hợp rename/copy thực vẫn pass.

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

Mô tả

What happened?

A binary modification under a directory containing the literal sequence b/ is parsed with the wrong file identity and incorrectly classified as a rename. The existing file assets b/icon.png becomes path: "icon.png", with oldPath: "assets b/icon.png b/assets".

I reproduced this by calling the unmodified production parseDiffToFiles with actual git diff output from an isolated repository. A control file at assets/icon.png parses correctly. This verifies the parser; I have not run the browser UI or a packaged Plannotator binary.

Minimal reproduction

From a Plannotator checkout, save this as repro-diff-path.ts and run bun repro-diff-path.ts:

import { parseDiffToFiles } from './packages/core/diff-files';

const patch = [
  'diff --git a/assets b/icon.png b/assets b/icon.png',
  'index a4b2576..e98258d 100644',
  'Binary files a/assets b/icon.png and b/assets b/icon.png differ',
  '',
].join('\n');

console.log(parseDiffToFiles(patch).map(({ path, oldPath, status }) =>
  ({ path, oldPath, status })));

This is real Git output: create and commit a PNG at assets b/icon.png, change its binary bytes, then run git diff --no-ext-diff --no-textconv. Git leaves these space-containing paths unquoted in this header.

Actual result

[{"path":"icon.png","oldPath":"assets b/icon.png b/assets","status":"renamed"}]

Expected result

[{"path":"assets b/icon.png","status":"modified"}]

oldPath should be absent because the file was not renamed.

Source and impact
  • parseDiffGitHeader uses /^diff --git a\/(.+) b\/(.+)$/ for unquoted headers. The first greedy group consumes through the b/ inside the new-side path.
  • parseDiffToFiles has no ---/+++ or rename metadata to fall back to for this binary modification, so it propagates incorrect paths and derives renamed.
  • The code-review app uses this parser for its file list, and listPatchFiles uses it for the server's changed-file set. findPatchFileEntry also uses the same header parser. Downstream file identity/path lookup therefore receives a path that does not name the changed file. These downstream implications are based on source inspection, not a browser reproduction.

A fix should cover unquoted equal-path binary headers containing b/, while preserving quoted paths and genuine rename/copy handling. Simply making the regex non-greedy also needs care: b/ can occur in the old-side path too.

Related reports checked

I searched issues and PRs for the parser name, binary paths, whitespace and diff headers. #628 concerns quoted/non-ASCII headers and is closed; this reproduction uses an unquoted header and still fails on the checked main snapshot.

Plannotator version

Source checkout at 76cbbecf8bfe67ad1c3f8713c0c0907663710fd5 (package.json: 0.29.2). The same parser file was rechecked on main before filing.

OS

Windows. Verification runtime: Node.js v24.22.3 with native TypeScript support and an extension-resolution hook for the repo's extensionless import; Git 2.56.0.windows.2. The Bun snippet above is the equivalent maintainer-facing reproduction; the measured output was obtained with Node calling the original source functions.

Agent

None / standalone source-level reproduction

Where did it happen?

Code review — shared diff parser

Browser

Not used.

Ngôn ngữ chính
TypeScript
Star
8.7k
Fork
649
Merge trung bình
14 giờ 26 phút
Pull request đã merge (30 ngày)
772

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 backnotprop/plannotator

Tất cả issue của backnotprop/plannotator

Issue tương tự

Thêm issue về TypeScript

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.