Commit Graph

3 Commits

Author SHA1 Message Date
Claude Bot
d43b3e3119 Normalize ucs2/utf16le encoding aliases
Addresses CodeRabbit review feedback:

**Issue**: ucs2 and utf16le were not being treated as equivalent aliases,
causing transcode("utf16le", "ucs2") to fail with "Unsupported encoding
combination" error.

**Fix**:
- Normalize ucs2 to utf16le before processing
- This ensures the same-encoding fast path works for both aliases
- All switch cases now treat them identically
- Removed ucs2 from supported encoding checks (redundant after normalization)

**Tests Added**:
- utf16le → ucs2 transcoding
- ucs2 → utf16le transcoding
- ucs2 → utf8 transcoding

All tests pass (22 custom + Node.js compatibility).

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-31 01:32:51 +00:00
Claude Bot
6d592d633b Fix ASCII 7-bit limit and add ASCII↔Latin1 transcoding
Addresses CodeRabbit review feedback:

1. **Enforce 7-bit ASCII limit (0x00-0x7F)**
   - UTF-8 → ASCII now clamps to 0x7F instead of 0xFF
   - UTF-16 → ASCII now clamps to 0x7F instead of 0xFF
   - Characters above 0x7F are replaced with '?'

2. **Implement ASCII ↔ Latin1 transcoding**
   - Added ASCII → Latin1 (simple copy, all ASCII is valid Latin1)
   - Added Latin1 → ASCII (clamp bytes > 0x7F to '?')
   - Fixes regression where these conversions would throw

3. **Add comprehensive tests**
   - Test ASCII to Latin1 conversion
   - Test Latin1 to ASCII with high byte replacement
   - Test 7-bit ASCII enforcement from UTF-8
   - Test Latin1 character preservation

All tests pass (19 custom + Node.js compatibility).

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-31 01:18:19 +00:00
Claude Bot
cd786fd0ba Implement transcode function for node:buffer
This commit adds support for the transcode function in node:buffer,
which converts Buffer contents between different character encodings.

Implementation:
- Added transcodeBuffer helper function in JSBuffer.cpp that performs
  encoding conversions using simdutf
- Supports utf8, utf16le/ucs2, latin1, and ascii encodings
- Invalid characters are replaced with '?' when transcoding to ASCII/Latin1
- Uses SIMDUTF for fast encoding conversions

Added comprehensive test suite covering:
- UTF-8 to ASCII/Latin1 with replacement chars
- UTF-8 to/from UTF-16LE
- Latin1 to/from UTF-8 and UTF-16LE
- Empty buffers and same-encoding passthrough
- Error handling for invalid inputs

Fixes #24235

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-31 00:54:19 +00:00