aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-11-03 19:29:07 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-11-03 19:29:07 -0700
commit303a5ea898cd1df71a00caabd326c74940b379fc (patch)
treedbeab694673c7e47be28b4f6a0f19f94d0ae395e /src
parentd502d0bcd6c2f908ffba1cbba149c3f833764f6f (diff)
downloadbun-303a5ea898cd1df71a00caabd326c74940b379fc.tar.gz
bun-303a5ea898cd1df71a00caabd326c74940b379fc.tar.zst
bun-303a5ea898cd1df71a00caabd326c74940b379fc.zip
[JSX] Fix regression with JSX entities
Diffstat (limited to 'src')
-rw-r--r--src/js_lexer.zig24
-rw-r--r--src/string_immutable.zig2
2 files changed, 20 insertions, 6 deletions
diff --git a/src/js_lexer.zig b/src/js_lexer.zig
index 8137c71db..505a45869 100644
--- a/src/js_lexer.zig
+++ b/src/js_lexer.zig
@@ -1999,7 +1999,6 @@ pub fn NewLexer(comptime json_options: JSONOptions) type {
lexer.previous_backslash_quote_in_jsx = backslash;
}
try lexer.step();
- // not sure about this!
break :string_literal;
},
else => {
@@ -2165,8 +2164,9 @@ pub fn NewLexer(comptime json_options: JSONOptions) type {
while (iterator.next(&cursor)) {
if (cursor.c == '&') {
- if (strings.indexOfChar(text[cursor.i..], ';')) |length| {
- const entity = text[cursor.i .. @as(usize, cursor.i) + length];
+ if (strings.indexOfChar(text[cursor.width + cursor.i ..], ';')) |length| {
+ const end = cursor.width + cursor.i;
+ const entity = text[end .. end + length];
if (entity[0] == '#') {
var number = entity[1..entity.len];
var base: u8 = 10;
@@ -2174,9 +2174,21 @@ pub fn NewLexer(comptime json_options: JSONOptions) type {
number = number[1..number.len];
base = 16;
}
- cursor.c = try std.fmt.parseInt(i32, number, base);
- cursor.i += @intCast(u32, length) + 1;
- cursor.width = 0;
+ cursor.c = std.fmt.parseInt(i32, number, base) catch |err| brk: {
+ switch (err) {
+ error.InvalidCharacter => {
+ lexer.addError(lexer.start, "Invalid JSX entity escape: {s}", .{entity}, false);
+ },
+ error.Overflow => {
+ lexer.addError(lexer.start, "JSX entity escape is too big: {s}", .{entity}, false);
+ },
+ }
+
+ break :brk strings.unicode_replacement;
+ };
+
+ cursor.i += @intCast(u32, length);
+ cursor.width = 1;
} else if (tables.jsxEntity.get(entity)) |ent| {
cursor.c = ent;
cursor.i += @intCast(u32, length) + 1;
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index 10f88fab9..c1ca706e9 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -873,3 +873,5 @@ test "sortDesc" {
}
pub usingnamespace @import("exact_size_matcher.zig");
+
+pub const unicode_replacement = 0xFFFD;