Fix: show embedded newlines in telemetry string values#3376
Open
ryanmelt-agent wants to merge 2 commits into
Open
Fix: show embedded newlines in telemetry string values#3376ryanmelt-agent wants to merge 2 commits into
ryanmelt-agent wants to merge 2 commits into
Conversation
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>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
\n,\r,\tinstead.preserveWhitespacedata flag so the underlyingv-textareacontinues to render embedded newlines as actual line breaks.RegExp.testfast path; values that contain no whitespace control characters pay only one cheap check (~30ns/call) before returning the original string unchanged.JSON.stringifyoutput from being mangled — the previous code did.replace(/\\n/g, ''), which silently swallowed the escaped\nsequences in stringified arrays/objects.Fixes #154
Performance
Microbenchmarked locally via a Node smoke script that replays the new
formatValueBase/escapeWhitespacelogic on representative inputs (200000 iterations each):\ns (replace path)preserveWhitespace: true(skip)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— addedescapeWhitespace, threadedoptions.preserveWhitespacethrough, and stopped silently dropping\nfrom JSON output.openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/VWidget.js— passpreserveWhitespacefrom the widget intoformatValueBase.openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/TextboxWidget.vue— setpreserveWhitespace: trueso embedded newlines survive intov-textarea.playwright/tests/packet-viewer.p.spec.ts— regression test: overrideINST HEALTH_STATUS ASCIICMDwith"line1\nline2\nline3"and assert the cell renders the literal escape sequence rather than truncating at the first newline.Test plan
pnpm lintinopenc3-cosmos-init/plugins/packages/openc3-vue-commonpasses.pnpm buildinopenc3-cosmos-init/plugins/packages/openc3-vue-commonsucceeds.\n/\r\n/\t/ mixed inputs, pluspreserveWhitespace, null, undefined, arrays, and objects (all green).displays embedded newlines in string telemetry valuestest inpacket-viewer.p.spec.ts.