Skip to content

Commit 263993d

Browse files
authored
fix(compiler): Properly encode hex values in Bytes literals (#2088)
1 parent 8d157f3 commit 263993d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

compiler/src/utils/literals.re

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,10 @@ let add_code_point = (buf, str, unicode) => {
385385
| "x" => Scanf.sscanf(numstr, "%x", x => x)
386386
| _ => Scanf.sscanf(esc ++ numstr, "%o", x => x)
387387
};
388-
if (Uchar.is_valid(code_point)) {
388+
if (unicode && Uchar.is_valid(code_point)) {
389389
Buffer.add_utf_8_uchar(buf, Uchar.of_int(code_point));
390+
} else if (!unicode) {
391+
Buffer.add_uint8(buf, code_point);
390392
} else {
391393
raise(IllegalUnicodeCodePoint(str));
392394
};

compiler/test/suites/strings.re

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ bar", 1))|},
376376

377377
// Bytes literals
378378
assertRun("bytes_literal", {|print(b"abc")|}, "<bytes: 61 62 63>\n");
379+
assertRun(
380+
"bytes_literal_hex",
381+
{|print(b"\xc3\x81\x24\x24\x00\x24\x99\xc3")|},
382+
"<bytes: c3 81 24 24 00 24 99 c3>\n",
383+
);
379384
assertRun(
380385
"bytes_literal_long",
381386
{|print(b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefg")|},

0 commit comments

Comments
 (0)