[Git][reproducible-builds/diffoscope][master] fix: parse header and hunksize strictly before context
Chris Lamb (@lamby)
gitlab at salsa.debian.org
Mon Feb 12 18:02:28 UTC 2024
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
4648dcfa by James Addison at 2024-02-12T18:02:11+00:00
fix: parse header and hunksize strictly before context
- - - - -
4 changed files:
- diffoscope/diff.py
- + tests/data/output_expected_363.html
- + tests/data/salsa-issue-363.diff.json
- tests/test_presenters.py
Changes:
=====================================
diffoscope/diff.py
=====================================
@@ -661,7 +661,8 @@ class SideBySideDiff:
"""
self.reset()
- for l in diff_split_lines(self.unified_diff, False):
+ diff_lines = iter(diff_split_lines(self.unified_diff, False))
+ for l in diff_lines:
self._bytes_processed += len(l) + 1
m = re.match(r"^--- ([^\s]*)", l)
if m:
@@ -689,8 +690,10 @@ class SideBySideDiff:
self.hunk_off2,
self.hunk_size2,
)
- continue
+ break
+ for l in diff_lines:
+ self._bytes_processed += len(l) + 1
if re.match(r"^\[", l):
yield from self.empty_buffer()
yield "C", l
=====================================
tests/data/output_expected_363.html
=====================================
@@ -0,0 +1,17 @@
+ class="diffoscope">
+<div class="difference">
+ <div class="diffheader">
+ <div class="diffcontrol">⊟</div>
+ <div><span class="diffsize">182 B</span></div>
+ <div id="top"><span class="source">example.sql</span>
+ <a class="anchor" href="#top">¶</a>
+ </div>
+ </div>
+<table class="diff">
+<colgroup><col class="colines"/><col class="coldiff"/>
+<col class="colines"/><col class="coldiff"/></colgroup>
+<tr style="display:none;"><td> </td><td> </td><td> </td><td> </td></tr>
+<tr class="diffhunk"><td colspan="2">Offset 1, 2 lines modified</td><td colspan="2">Offset 1, 2 lines modified</td></tr>
+<tr class="diffunmodified"><td class="diffline">1 </td><td class="diffpresent">--<span class="dp">·</span>unrelated<span class="dp">·</span>comment</td><td class="diffline">1 </td><td class="diffpresent">--<span class="dp">·</span>unrelated<span class="dp">·</span>comment</td></tr>
+<tr class="diffchanged"><td class="diffline">2 </td><td class="diffpresent">--<span class="dp">·</span>comment<span class="dp">·</span>containing<span class="dp">·</span>a<span class="dp">·</span>timestamp:<span class="dp">·</span>2024-02-12T02:0<del>7</del>:00.000Z</td><td class="diffline">2 </td><td class="diffpresent">--<span class="dp">·</span>comment<span class="dp">·</span>containing<span class="dp">·</span>a<span class="dp">·</span>timestamp:<span class="dp">·</span>2024-02-12T02:0<ins>8</ins>:00.000Z</td></tr>
+</table></div>
=====================================
tests/data/salsa-issue-363.diff.json
=====================================
@@ -0,0 +1,6 @@
+{
+ "diffoscope-json-version": 1,
+ "source1": "example.sql",
+ "source2": "example.sql",
+ "unified_diff": "@@ -1,2 +1,2 @@\n -- unrelated comment\n--- comment containing a timestamp: 2024-02-12T02:07:00.000Z\n+-- comment containing a timestamp: 2024-02-12T02:08:00.000Z\n"
+}
=====================================
tests/test_presenters.py
=====================================
@@ -200,6 +200,25 @@ def test_html_regression_875281(tmpdir, capsys):
)
+def test_html_presentation_issue_363(tmpdir, capsys):
+ filename = "salsa-issue-363.diff.json"
+ diff_data = get_data(filename)
+ diff_path = str(tmpdir.join(filename))
+ with open(diff_path, "w") as fp:
+ fp.write(diff_data)
+ report_path = str(tmpdir.join("report.html"))
+ out = run(
+ capsys,
+ "--html",
+ report_path,
+ f"--load-existing-diff={diff_path}",
+ )
+ assert out == ""
+
+ with open(report_path, "r", encoding="utf-8") as f:
+ assert extract_body(f.read()) == get_data("output_expected_363.html")
+
+
def test_limited_print():
def fake(x):
return None
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/4648dcfa6a9afda4a5c93bd03c262dbe51e4f866
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/4648dcfa6a9afda4a5c93bd03c262dbe51e4f866
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20240212/f729158d/attachment.htm>
More information about the rb-commits
mailing list