Repository navigation
feat(js/ts/python/dart/rust/beam): support Convert.ToHexString, ToHexStringLower and FromHexString - #5204
Merged
MangelMaxime merged 6 commits intoOct 30, 2026
Conversation
…xString Map them to new String.toHexString, toHexStringLower and fromHexString library functions, next to the base64 ones. The offset and length overloads of ToHexString and ToHexStringLower are supported too. As on .NET, FromHexString accepts either case and raises FormatException for an odd length or a non-hex character, and returns a Uint8Array like FromBase64String. Null arguments raise ArgumentNullException and a bad offset or length raises ArgumentOutOfRangeException. The tests' raisedExceptionType helper now also reports ArgumentNullException and FormatException.
…exString Map them, including the offset and length overloads, to a new fable_library convert module. It lives outside string_.py because it raises .NET exceptions from system.py, which imports string_.py. As on .NET, FromHexString accepts either case and raises FormatException for an odd length or a non-hex character (bytes.fromhex alone would skip whitespace), and returns a byte array. Null arguments raise ArgumentNullException and a bad offset or length raises ArgumentOutOfRangeException. The tests' raisedExceptionType helper now also reports ArgumentNullException and FormatException.
…String Map them, including the offset and length overloads, to new toHexString, toHexStringLower and fromHexString functions in String.dart, which raise the .NET exceptions from System.dart like Async.dart does. As on .NET, FromHexString accepts either case and raises FormatException for an odd length or a non-hex character, and a bad offset or length raises ArgumentOutOfRangeException. The tests' raisedExceptionType helper now also reports ArgumentNullException and FormatException.
…String Map them, including the offset and length overloads, to new fable_convert functions that take byte arrays like to_base64, plus arrays kept in the process dictionary (List.toArray), and use binary:encode_hex and binary:decode_hex (OTP 24). The lowercase variant lowercases the result, since binary:encode_hex/2 needs OTP 26. As on .NET, FromHexString accepts either case and raises FormatException for an odd length or a non-hex character, and returns a byte array like from_base64. Null arguments raise ArgumentNullException and a bad offset or length raises ArgumentOutOfRangeException. The tests' raisedExceptionType helper now also reports ArgumentNullException and FormatException.
fromHexString dropped a trailing digit, so "abc" gave [| 0xABuy |]. It now panics like it does for a non-hex character, where .NET raises FormatException.
MangelMaxime
force-pushed
the
support-convert-hex
branch
from
October 30, 2026 21:26
024c80e to
4d49e68
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
Convert.ToHexString,ToHexStringLowerandFromHexStringto JS/TS, Python, Dart and Beam, where they were compile errors. One commit per target, plus a Rust fix.ToHexString(bytes)andToHexString(bytes, offset, length)give uppercase digits,ToHexStringLowerlowercase ones.FromHexString(s)accepts either case and raisesFormatExceptionwith .NET's messages for an odd length or a non-hex character. It returns a byte array (aUint8Arrayon JS/TS, likeFromBase64String).ArgumentNullException, and a bad offset or length raisesArgumentOutOfRangeException, checked in .NET's order and with its parameter names.convert.py, sincesystem.pyimportsstring_.py. Beam usesbinary:encode_hex/decode_hex(OTP 24).FromHexStringnow panics on an odd length instead of dropping the last digit.raisedExceptionTypehelper now also reportsArgumentNullExceptionandFormatException.Differences from .NET: out-of-range messages use Fable's existing wording, and
FromHexStringcounts UTF-8 bytes on Beam and code points on Python, so some non-ASCII strings get the otherFormatExceptionmessage.Not covered: the
Try*,OperationStatusand span overloads, the offset and length overloads on Rust, and null checks on Dart.