One function

combine_code_and_description in microsoft/sarif-tools

The author described this change as Avoid word wrap crash when issue code long (#52). It counts as a record because the check below fails on the code as it stood at 1c158cbee and passes on 4bf8cad72, with nothing else changed between the two runs.

Fix saved2024-07-04
Sharing licenceMIT · LICENSE
Change size+16 6

What the code was meant to do, written into the code itself as a docstring

Combine code and description into one string, keeping total length under 120 characters.

The change

55 length_budget = 120
66 if code:
77 code = code.strip()
8- length_budget -= len(code) + 1
8+ length_budget -= len(code) + 1 # Allow issue code and space character
9+ continuation_placeholder = " ..."
910 # Allow extra space when truncating for continuation characters
10- length_budget_pre_continuation = length_budget - 20
11+ length_budget_pre_continuation = length_budget - len(continuation_placeholder)
12+ if length_budget_pre_continuation < 10:
13+ # Don't include description if it would be very short due to long code
14+ return code
1115 if description:
1216 if "\n" in description:
1317 description = description[: description.index("\n")]
1519 if description:
1620 if len(description) > length_budget:
1721 shorter_description = textwrap.shorten(
18- description, width=length_budget_pre_continuation, placeholder=" ..."
22+ description,
23+ width=length_budget_pre_continuation,
24+ placeholder=continuation_placeholder,
1925 )
20- if len(shorter_description) < 40:
21- description = description[:length_budget_pre_continuation] + " ..."
26+ if len(shorter_description) < length_budget_pre_continuation - 40:
27+ # Word wrap shortens the description significantly, so truncate mid-word instead
28+ description = (
29+ description[:length_budget_pre_continuation]
30+ + continuation_placeholder
31+ )
2232 else:
2333 description = shorter_description
2434 if code:
2535 return f"{code.strip()} {description}"
2636 return description
2737 if code:
28- return code.strip()
38+ return code
2939 return "<NONE>"

The check that tells the two apart

failpass·tests/test_sarif_file_utils.py::test_combine_code_and_description_long_desc

Check file tests/test_sarif_file_utils.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it1c158cbee8c4682c61e69fb5646f160af578bd16
Broken version dated2024-07-01
Modulesarif.sarif_file_utils
Units changedcombine_code_and_description
Fingerprintc5604bfa0d83aa78
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.