Skip to content

fix(jsonview): avoid width underflow in static string rendering - #117

Open
sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix/static-json-narrow-width
Open

fix(jsonview): avoid width underflow in static string rendering#117
sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix/static-json-narrow-width

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Avoid converting a negative remaining display width into an enormous unsigned truncation limit when rendering static JSON strings in narrow terminals.

Problem

formatResult currently truncates long strings with:

truncate.String(str, uint(width-1))

Object and array rendering can pass a non-positive width after subtracting the rendered key or numbering width. Converting width-1 to uint then wraps the negative value to a very large number, so the string is effectively not truncated and can spill far beyond the available terminal width.

Fix

Centralize string-width handling in a small helper that:

  • returns no string content when no width is available;
  • renders a single ellipsis when exactly one column is available;
  • preserves strings that already fit;
  • only converts a verified positive truncation width to uint.

Normal-width output is unchanged.

Regression coverage

Added focused tests covering:

  • a non-positive string width, which previously retained the full string because of unsigned wraparound;
  • the one-column case, which now deterministically renders a single ellipsis.

Validation

The branch is based directly on current upstream main (ee92673a416c0851a5fe8907a2453db7bd450633) and contains one signed commit touching only the static JSON renderer and its focused regression test. Full Go test execution is left to repository CI.

Risk

Low. The behavior change is limited to string values whose available display width is zero or too small to contain the original value.

Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 20, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant