Skip to content

Fix: show embedded newlines in telemetry string values#3376

Open
ryanmelt-agent wants to merge 2 commits into
OpenC3:mainfrom
ryanmelt-agent:fix/ope-20-newlines-telemetry
Open

Fix: show embedded newlines in telemetry string values#3376
ryanmelt-agent wants to merge 2 commits into
OpenC3:mainfrom
ryanmelt-agent:fix/ope-20-newlines-telemetry

Conversation

@ryanmelt-agent
Copy link
Copy Markdown

Summary

  • Telemetry string values with embedded newlines were silently truncated in the Packet Viewer (and any other single-line value display). Render them as the visible escape sequences \n, \r, \t instead.
  • TEXTBOX screen widgets opt out via a preserveWhitespace data flag so the underlying v-textarea continues to render embedded newlines as actual line breaks.
  • The escape uses a single module-level RegExp.test fast path; values that contain no whitespace control characters pay only one cheap check (~30ns/call) before returning the original string unchanged.
  • Stops JSON.stringify output from being mangled — the previous code did .replace(/\\n/g, ''), which silently swallowed the escaped \n sequences in stringified arrays/objects.

Fixes #154

Performance

Microbenchmarked locally via a Node smoke script that replays the new formatValueBase / escapeWhitespace logic on representative inputs (200000 iterations each):

Case ns/call
Plain string, no whitespace (fast path) ~31
String with embedded \ns (replace path) ~158
TEXTBOX preserveWhitespace: true (skip) ~21

For context, the Packet Viewer typically renders ~10–100 values at the configured poll interval (default 1s), so the worst case adds a few microseconds per refresh — well under perceptual thresholds.

Files changed

  • openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/FormatValueBase.js — added escapeWhitespace, threaded options.preserveWhitespace through, and stopped silently dropping \n from JSON output.
  • openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/VWidget.js — pass preserveWhitespace from the widget into formatValueBase.
  • openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/TextboxWidget.vue — set preserveWhitespace: true so embedded newlines survive into v-textarea.
  • playwright/tests/packet-viewer.p.spec.ts — regression test: override INST HEALTH_STATUS ASCIICMD with "line1\nline2\nline3" and assert the cell renders the literal escape sequence rather than truncating at the first newline.

Test plan

  • pnpm lint in openc3-cosmos-init/plugins/packages/openc3-vue-common passes.
  • pnpm build in openc3-cosmos-init/plugins/packages/openc3-vue-common succeeds.
  • Node smoke test exercises the escape on plain / \n / \r\n / \t / mixed inputs, plus preserveWhitespace, null, undefined, arrays, and objects (all green).
  • CI: full Playwright run including the new displays embedded newlines in string telemetry values test in packet-viewer.p.spec.ts.

Newlines, carriage returns, and tabs embedded in string telemetry values
were silently truncating the displayed cell at the first control char.
Escape them as \n / \r / \t for single-line displays such as Packet
Viewer, and let TEXTBOX widgets keep raw newlines so v-textarea renders
multi-line output.

The escape uses a single module-level RegExp.test fast path so values
without embedded whitespace pay only one cheap check (~30ns/call) before
returning the original string. JSON.stringify output is now preserved
verbatim rather than having literal "\n" sequences silently stripped.

Fixes OpenC3#154

Co-Authored-By: Paperclip <noreply@paperclip.ing>
- Use optional chaining `options?.preserveWhitespace` instead of the
  short-circuit `options && options.x` pattern (S6582).
- Use `String.raw` templates for the literal `\n` / `\r` / `\t` return
  values in `escapeWhitespace`, and for the embedded Ruby source in the
  Playwright override test, so backslash escapes appear in the source
  exactly as they appear in the produced string (S7780).

No behavior change; output strings are byte-for-byte identical to the
prior implementation. Verified with `pnpm lint` (vue-common) and
`pnpm prettier --check` (playwright) — both clean.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@sonarqubecloud
Copy link
Copy Markdown

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.

Support displaying newline characters in telemetry string values

2 participants