Skip to content

Ensure UTF-8 JSON output#2

Merged
DTTerastar merged 1 commit intomainfrom
codex/check-utf-8-encoding-for-json
Aug 24, 2025
Merged

Ensure UTF-8 JSON output#2
DTTerastar merged 1 commit intomainfrom
codex/check-utf-8-encoding-for-json

Conversation

@DTTerastar
Copy link
Contributor

@DTTerastar DTTerastar commented Aug 24, 2025

Summary

  • extract UTF-8-safe json_encode helper
  • add unit tests covering multibyte SSIDs and control characters
  • configure native PlatformIO environment for tests

Testing

  • pio test -e native
  • npm test (fails: Missing script "test")
  • pio --version

https://chatgpt.com/codex/tasks/task_e_68ab42a94d64832491daf767296392a9

Summary by CodeRabbit

  • New Features

    • JSON API responses now explicitly declare UTF-8 charset for improved client compatibility.
  • Bug Fixes

    • Improved JSON string escaping for control characters while preserving UTF-8 content.
  • Refactor

    • Centralized JSON encoding logic to a shared utility for consistency across responses.
  • Tests

    • Added unit tests validating UTF-8 preservation and control character escaping in JSON output.
  • Chores

    • Updated development configuration with a native build environment and clarified serial monitor speed settings.

@coderabbitai
Copy link

coderabbitai bot commented Aug 24, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Centralized JSON string escaping into a new utility header, updated HTTP JSON responses to include UTF-8 charset, added PlatformIO native test environment, and introduced Arduino String stubs plus unit tests validating JSON escaping and UTF-8 preservation.

Changes

Cohort / File(s) Summary
Build config (PlatformIO)
platformio.ini
Added [env:native] with platform = native, test_build_src = false, and build_flags = -Isrc -Itest/stubs. Kept monitor_speed = 115200 with formatting change.
WiFi settings JSON responses
src/HeadlessWiFiSettings.cpp
Replaced local json_encode with utility include json_utils.h. Changed JSON response content type to application/json; charset=utf-8 for /wifi/options/, /wifi/scan, and /wifi (GET).
JSON utility
src/json_utils.h
New inline JSON encoder for Arduino String: escapes quotes, backslashes, control chars (\\b, \\f, \\n, \\r, \\t), and encodes chars < 0x20 as \\uXXXX. Inline in anonymous namespace.
Arduino stubs for tests
test/stubs/Arduino.h
New minimal String class stub (constructors, length(), isEmpty(), operator[], operator+=, c_str()), backed by std::string.
Unit tests for JSON encoding
test/test_json_encode/test_main.cpp
Added Unity tests: UTF-8 preserved ("O’Reilly" unchanged) and control-char escaping ("line\\nfeed"). Includes main to run tests under native env.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I nibble bytes with whiskers keen,
Escaping slashes, keeping strings clean.
UTF-8 shines, a crisp new light,
Headers whisper, “charset’s right.”
Tests hop green—okey-dokey!
Code-rabbit thumps: JSON’s pokey 🥕✨


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 36ae1b7 and 3f40fd0.

📒 Files selected for processing (5)
  • platformio.ini (1 hunks)
  • src/HeadlessWiFiSettings.cpp (4 hunks)
  • src/json_utils.h (1 hunks)
  • test/stubs/Arduino.h (1 hunks)
  • test/test_json_encode/test_main.cpp (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/check-utf-8-encoding-for-json

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@DTTerastar DTTerastar merged commit 38ec581 into main Aug 24, 2025
1 of 2 checks passed
@DTTerastar DTTerastar deleted the codex/check-utf-8-encoding-for-json branch August 24, 2025 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant