Skip to content

Work diff canvas splits hunk lines at form feeds and Unicode line separators #281

Closed

Description

@NopeCharon

Expected and actual behavior / 实际现象与期望

parse_unified_diff (server/unified_diff.py) should treat each patch line as Git emitted it. It iterates over source.splitlines(), and str.splitlines() breaks not only at \n but also at form feed (\f), vertical tab, \x1c–\x1e, \x85, U+2028 and U+2029. Such characters inside a source line split that line in two:

  • the rest of the line becomes a separate patch line; if it starts with -, + or a space, it is rendered as a phantom removed/added/context line, and the additions/deletions counts and every following line number are wrong;
  • otherwise the rest is silently dropped, so the shown line is truncated.

Form feeds are common page separators in Python, C and Lisp sources, and U+2028 appears in JavaScript/JSON strings.

Steps to reproduce / 复现步骤

In a Git repository, commit app.py containing:

def a():
    pass
<form feed>
def b():
    pass

Change it to return 1 in a() and replace the last line with x = "a<form feed>-b", then run:

import subprocess
from server.unified_diff import parse_unified_diff

patch = subprocess.run(["git", "diff", "HEAD", "--"], capture_output=True, text=True).stdout
file = parse_unified_diff(patch)["files"][0]
print(file["additions"], file["deletions"], file["hunks"][0]["lines"][-2:])

Actual: 2 3. The added line is shown as x = "a, followed by a phantom removed line b" at old line 6.
Expected: 2 2, with the added line x = "a\f-b".

Relevant environment / 使用环境

Platform-independent; current main (fdd672e).

Sanitized evidence / 错误信息或截图(请先脱敏)

Git terminates patch lines with \n only. Splitting on \n and removing a trailing \r keeps the current handling of CRLF content and CRLF-framed patches.

Related issues or fixes / 相关问题或修复

#274 / #275 fixed a different parser defect in the same function.

Activity

  1. added a commit that references this issue on Nov 9, 2026
    f86c72a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions