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>
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>
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>