Skip to content

Fix JSON encoding to preserve Unicode characters like µA#2707

Merged
jmthomas merged 1 commit intomainfrom
fix_ruby_encoding
Jan 5, 2026
Merged

Fix JSON encoding to preserve Unicode characters like µA#2707
jmthomas merged 1 commit intomainfrom
fix_ruby_encoding

Conversation

@jmthomas
Copy link
Copy Markdown
Member

@jmthomas jmthomas commented Jan 2, 2026

Summary

  • Fixes regression from PR Queue binary #2535 where Unicode characters (e.g., µA for micro-Ampères, °C) were incorrectly encoded as raw byte arrays instead of readable text
  • The fix removes an overly aggressive early return that treated all ASCII-8BIT strings with bytes > 127 as binary data
  • Now relies on UTF-8 validity checking to distinguish binary data (invalid UTF-8) from Unicode text (valid UTF-8)

Test plan

  • Added Ruby regression tests for Unicode preservation (openc3/spec/io/json_rpc_spec.rb)
  • Added Python regression tests to prevent future issues (openc3/python/test/io/test_json_rpc.py)
  • Verified binary data (e.g., \xDE\xAD\xBE\xEF) still encodes as raw object
  • Verified Unicode text (e.g., 0.5 µA, 25 °C) is preserved as readable string
  • Test in Packet Viewer with MECH packet CURRENT field that has units "µA"

🤖 Generated with Claude Code

The change in PR #2535 to support binary commands incorrectly encoded
valid UTF-8 Unicode characters (e.g., µA for micro-Ampères) as raw byte
arrays. This was caused by an overly aggressive early return that treated
all ASCII-8BIT strings with bytes > 127 as binary data.

The fix removes this early return and relies on UTF-8 validity checking
to distinguish between true binary data (invalid UTF-8) and Unicode text
(valid UTF-8 stored in ASCII-8BIT strings).

Added regression tests for both Ruby and Python to prevent future issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.23%. Comparing base (0320a14) to head (d36ff2d).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2707      +/-   ##
==========================================
- Coverage   79.23%   79.23%   -0.01%     
==========================================
  Files         664      664              
  Lines       52823    52821       -2     
  Branches      734      734              
==========================================
- Hits        41854    41851       -3     
- Misses      10889    10890       +1     
  Partials       80       80              
Flag Coverage Δ
python 81.14% <ø> (+<0.01%) ⬆️
ruby-api 84.76% <ø> (-0.06%) ⬇️
ruby-backend 82.15% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@clayandgen clayandgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unicode chars fix confirmed
Screenshot 2026-01-05 at 9 44 28 AM
Screenshot 2026-01-05 at 9 44 08 AM

@jmthomas jmthomas merged commit a31f4e2 into main Jan 5, 2026
27 of 28 checks passed
@jmthomas jmthomas deleted the fix_ruby_encoding branch January 5, 2026 19:42
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.

2 participants