Skip to content

Conversation

@mknos
Copy link
Contributor

@mknos mknos commented Feb 25, 2025

  • When processing an append ("a") command in an ed-style diff, line number ranges are not parsed correctly
  • If a range (e.g. "1,2") is given as a prefix to "a", the 2nd address ("2") is used as the target address
  • Regular diff tools don't output "a" commands with 2 addresses so this is a corner case
  • ed-style diffs can be pasted from a previous ed editor session or typed manually, so having extra validation here is helpful
  • To test this, I bypassed the code for running an external ed program
  • I modified a diff generated by "diff -e", changing the "322a" command to "1,322a"... the file is patched successfully
%cat bad.diffe 
1,322a
	my $Maxlen = 1;		# longest string for current directory
.
317,318d
113d
%perl patch -e ls bad.diffe 
Hmm...  Looks like an ed diff to me...
Patching file ls using Plan A...
Hunk #1 succeeded at 113
Hunk #2 succeeded at 317
Hunk #3 succeeded at 322
done
%cmp ls ls2

* When processing an "a" (append text) command in an ed-style diff, line number ranges are not parsed correctly
* If a range (e.g. "1,2") is given as a prefix to "a", the 2nd address ("2") is used as the target address
* Regular diff tools don't output "a" commands with 2 addresses
* ed-style diffs can be pasted from a previous ed editor session or typed manually, so having extra validation here is helpful
* To test this, I bypassed the code for running an external ed program
* I modified a diff generated by "diff -e", changing the "322a" command to "1,322a"... the file is patched successfully

%cat bad.diffe 
1,322a
	my $Maxlen = 1;		# longest string for current directory
.
317,318d
113d
%perl patch -e ls bad.diffe 
Hmm...  Looks like an ed diff to me...
Patching file ls using Plan A...
Hunk briandfoy#1 succeeded at 113
Hunk briandfoy#2 succeeded at 317
Hunk briandfoy#3 succeeded at 322
done
%cmp ls ls2
@github-actions github-actions bot added Type: enhancement improve a feature that already exists Priority: low get to this whenever Program: patch The patch program labels Feb 25, 2025
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:25 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing February 25, 2025 01:26 — with GitHub Actions Inactive
@coveralls
Copy link

coveralls commented Feb 25, 2025

Pull Request Test Coverage Report for Build 13511545565

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 72.349%

Totals Coverage Status
Change from base Build 13503527620: 0.0%
Covered Lines: 348
Relevant Lines: 481

💛 - Coveralls

@mknos
Copy link
Contributor Author

mknos commented Feb 25, 2025

SEE ALSO:
https://lists.gnu.org/archive/html/bug-patch/2025-02/msg00019.html

I submitted this other bug report because GNU patch seemed to fail when processing my test input file with [valid] ed command "1,322a". See how test cases for this project can help the wider Loonix world...

@briandfoy briandfoy self-assigned this Feb 25, 2025
@briandfoy briandfoy added Type: bug an existing feature does not work and removed Type: enhancement improve a feature that already exists labels Feb 25, 2025
@briandfoy
Copy link
Owner

changes: handle line range correctly for append operations

@briandfoy briandfoy merged commit f2d8543 into briandfoy:master Feb 25, 2025
23 checks passed
@github-actions github-actions bot added Status: accepted The fix is accepted labels Feb 25, 2025
@briandfoy briandfoy removed the Priority: low get to this whenever label Feb 26, 2025
@briandfoy briandfoy added Status: released there is a new release with this fix and removed Status: accepted The fix is accepted labels Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Program: patch The patch program Status: released there is a new release with this fix Type: bug an existing feature does not work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants