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.
Projectmicrosoft/sarif-tools
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
| 5 | 5 | length_budget = 120 | |
| 6 | 6 | if code: | |
| 7 | 7 | code = code.strip() | |
| 8 | - | length_budget -= len(code) + 1 | |
| 8 | + | length_budget -= len(code) + 1 # Allow issue code and space character | |
| 9 | + | continuation_placeholder = " ..." | |
| 9 | 10 | # 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 | |
| 11 | 15 | if description: | |
| 12 | 16 | if "\n" in description: | |
| 13 | 17 | description = description[: description.index("\n")] | |
| ⋯ | |||
| 15 | 19 | if description: | |
| 16 | 20 | if len(description) > length_budget: | |
| 17 | 21 | shorter_description = textwrap.shorten( | |
| 18 | - | description, width=length_budget_pre_continuation, placeholder=" ..." | |
| 22 | + | description, | |
| 23 | + | width=length_budget_pre_continuation, | |
| 24 | + | placeholder=continuation_placeholder, | |
| 19 | 25 | ) | |
| 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 | + | ) | |
| 22 | 32 | else: | |
| 23 | 33 | description = shorter_description | |
| 24 | 34 | if code: | |
| 25 | 35 | return f"{code.strip()} {description}" | |
| 26 | 36 | return description | |
| 27 | 37 | if code: | |
| 28 | - | return code.strip() | |
| 38 | + | return code | |
| 29 | 39 | return "<NONE>" | |
The check that tells the two apart
fail→pass·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.