Skip to content
Snippets Groups Projects
Commit 4648dcfa authored by James Addison's avatar James Addison :speech_balloon: Committed by Chris Lamb
Browse files

fix: parse header and hunksize strictly before context

parent 00418fb4
No related branches found
No related tags found
1 merge request!136fix: parse header and hunksize strictly before context
Pipeline #638014 passed
......@@ -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
......
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>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</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>
{
"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"
}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment