Skip to content

fix(log): simplify JSON log serialization for invalid UTF-8#61166

Draft
joshtrichards wants to merge 1 commit into
masterfrom
jtr/fix-logDetails-serialization
Draft

fix(log): simplify JSON log serialization for invalid UTF-8#61166
joshtrichards wants to merge 1 commit into
masterfrom
jtr/fix-logDetails-serialization

Conversation

@joshtrichards

@joshtrichards joshtrichards commented Jun 10, 2026

Copy link
Copy Markdown
Member

Summary

Make LogDetails::logDetailsAsJSON() best-effort and deterministic by letting json_encode() handle malformed UTF-8 directly.

Instead of probing strings and attempting to guess their original encoding with mb_detect_encoding() / mb_convert_encoding(), this change:

  • removes the per-value fallback loop
  • uses JSON_INVALID_UTF8_SUBSTITUTE to sanitize invalid byte sequences
  • keeps JSON_PARTIAL_OUTPUT_ON_ERROR as a defensive fallback for logging

Why

This code path is used for logging, so the priority is to emit usable JSON rather than fail or spend extra work trying to recover the original encoding (which can't be done reliably anyhow - so this is a more "honest" implementation).

The implementation is simpler and should be faster in both the common case (valid UTF-8) and the less common case (invalid UTF-8) by avoiding per-field encoding checks and encoding detection/conversion.

Notes

  • Behavior for malformed UTF-8 changes from "best-effort repair" to deterministic substitution.
  • Valid UTF-8 input should be unaffected.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards joshtrichards added this to the Nextcloud 35 milestone Jun 10, 2026
@joshtrichards joshtrichards added 2. developing Work in progress feature: logging performance 🚀 ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring) labels Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress feature: logging performance 🚀 ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant