sebastianbergmann / diff

Diff implementation
BSD 3-Clause "New" or "Revised" License
7.58k stars 85 forks source link

Fixed range parsing #115

Closed dg closed 1 year ago

dg commented 1 year ago

Fixes two errors when parsing diff files

1) the range can be zero, for example if lines are only deleted or added 2) isset($match['startrange']) is always true

SpacePossum commented 1 year ago

Hi!

These changes look valid to me, nice catch :+1: : )

Sadly the CI doesn't run anymore, which seems not related to your changes.

dg commented 1 year ago

I honestly have no idea why it passes in master (https://github.com/dg/sebastianbergmann-diff/actions/runs/4495014297), but it doesn't pass in any other branch (https://github.com/dg/sebastianbergmann-diff/actions/runs/4491522850)

sebastianbergmann commented 1 year ago

I honestly have no idea why it passes in master (https://github.com/dg/sebastianbergmann-diff/actions/runs/4495014297), but it doesn't pass in any other branch (https://github.com/dg/sebastianbergmann-diff/actions/runs/4491522850)

Should work now after 9f7efbcf702e0ff2f688b43c088c3342a7c216d4.

sebastianbergmann commented 1 year ago

Thank you!

SpacePossum commented 1 year ago

thansk @dg :+1: :)

dg commented 1 year ago

One more thing. It's not a bug in the parser. It's just a weird meaning of the numbers 🤯 I haven't found any expanation, just a mention here https://www.artima.com/weblogs/viewpost.jsp?thread=164293

The first number is the start line of the chunk in the old or new file. The second number is chunk size in that file; it and the comma are omitted if the chunk size is 1. (Email from a reader suggests that this omission is optional and may be phased out.) If the chunk size is 0, the first number is one lower than one would expect (it is the line number after which the chunk should be inserted or deleted; in all other cases it gives the first line number or the replaced range of lines).

If you want, I'll post a PR to readme.

sebastianbergmann commented 1 year ago

If you want, I'll post a PR to readme.

That would be appreciated, thanks.