Skip to content

(diff) Won't highlight hunk headers with a single number instead of a number pair #4227

Closed
@sushicw

Description

@sushicw

Describe the issue
Diff is looking for hunk header that looks like this:

@@ -<num>,<num> +<num>,<num> @@

However, it's OK to omit the second number of each pair in some cases, see https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html

If a hunk contains just one line, only its start line number appears. Otherwise its line numbers look like ‘start,count’. An empty hunk is considered to start at the line that follows the hunk.

If a hunk and its context contain two or more lines, its line numbers look like ‘start,count’. Otherwise only its end line number appears. An empty hunk is considered to end at the line that precedes the hunk.

So these should also be valid, for example:

@@ -<num> +<num> @@
@@ -<num>,<num> +<num> @@

Which language seems to have the issue?
This is using diff.

Are you using highlight or highlightAuto?

highlight

Sample Code to Reproduce

See above

Expected behavior

The above examples should also be highlighted as hljs-meta.

Additional context

I can see the exact regexp causing this at

/^@@ +-\d+,\d+ +\+\d+,\d+ +@@/,

It can probably be simply replaced with this:

/^@@ +-\d+(?:,\d+)? +\+\d+(?:,\d+)? +@@/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions