log: Remove trailing and embedded newlines from log messages

bitcoin/bitcoin: PR #36904

1 suggestion

Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · CTransaction::ToString() flattens the GUI transaction debug view

When log categories are enabled, the GUI transaction-details debug panel now renders inputs, witnesses and outputs as one paragraph instead of separate lines.

Location: src/primitives/transaction.cpp:118 (head).

Details and suggested fix

src/qt/transactiondesc.cpp also consumes this string through GUIUtil::HtmlEscape(wtx.tx->ToString(), true), which converts newlines into <br> elements. Previously, the header and each input, witness and output occupied separate lines. The new formatter removes those breaks, and HTML collapses the four-space separators, making transactions with multiple entries harder to scan. Avoiding \x0a escapes in the log does not require flattening this HTML presentation. Keep the single-line formatter for logging, but build the GUI layout separately by iterating the inputs, witnesses and outputs, HTML-escaping each entry and inserting explicit <br> separators.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Embedded newlines were escaped to prevent untrusted input from masquerading as independent node log records, including input supplied by restricted RPC users.

The description of #35833 demonstrates forged error records injected through rejected RPC method names and wallet names. The single-line convention therefore protects record provenance, rather than merely imposing a formatting preference. Removing embedded newlines from diagnostic producers intersects that convention, but is distinct from the logger's protection against untrusted content.

Source 1

Escaping was preferred to deleting or sanitizing characters because diagnostics should retain the actual input while preventing control-character effects.

The earlier control-character filter explicitly preserved troublesome bytes as escapes for troubleshooting and protected terminal output. In #35833, a reviewer objected that sanitization could misleadingly make a rejected method look like an allowed method. This establishes a readability requirement of faithful, distinguishable diagnostic content—not a requirement that all human-facing diagnostics use one physical line.

Source 1 · Source 2 · Source 3

Preserving multiline log presentation was considered, but the proposed SplitLines exception was dropped after it allowed untrusted text to regain the appearance of separate records.

The historical discussion explicitly traded nicer multiline output against injection safety and removed the exception. Another inline comment treated exception separator lines as optional and considered an ordinary warning reasonable. These sources do not establish a requirement to retain multiline exception banners in the log, nor do they decide how separately displayed stderr or GUI text must be laid out.

Source 1 · Source 2 · Source 3

Ralph's inferences

Stripping a single trailing newline is plausibly a compatibility bridge for legacy newline-terminated logging calls: the conventional terminator need not become a visible escape, while embedded newlines remain data rather than record boundaries.

The pinned base exception formatter ends its message with a newline and passes it into LogWarning. That is a concrete legacy producer compatible with the stated trailing-newline carve-out. This explains the compatibility purpose, but the inspected historical sources do not explicitly justify the exact one-newline rule.

Source 1

The logger's single-record requirement does not itself imply either preserving or eliminating multiline presentation outside the logger; the exception change also changes a separate stderr presentation.

At the pinned base, PrintExceptionContinue sends its multiline message both to LogWarning and directly to std::cerr. At the head, it constructs a single-line message and still sends it independently to both destinations. Thus the log-safety rationale alone does not settle the stderr readability choice. No inspected source establishes a mandatory multiline stderr format, and the corresponding GUI transaction-presentation question remains unverified rather than resolved by the logging convention.

Source 1 · Source 2