Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/bun.js/ConsoleObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@

pub fn canHaveCircularReferences(tag: Tag) bool {
return switch (tag) {
.Function, .Array, .Object, .Map, .Set, .Error, .Class, .Event => true,
.Function, .Array, .Object, .Map, .Set, .Error, .Class, .Event, .JSX => true,

Check failure on line 1139 in src/bun.js/ConsoleObject.zig

View check run for this annotation

Claude / Claude Code Review

Same JSX crashes remain in pretty_format.zig (JestPrettyFormat)

The same two crashes also exist in the near-duplicate formatter `src/bun.js/test/pretty_format.zig` (used by `bun test` for expect() failure diffs and snapshots). There, `canHaveCircularReferences()` at line 328 still omits `.JSX`, and line 1542-1543 still does `props.getObject().?` with the now-invalid "SAFETY: JSX props are always an object" comment — so the same Fuzzilli input will still stack-overflow / panic when rendered by `JestPrettyFormat`. The fix should be mirrored there.
Comment thread
claude[bot] marked this conversation as resolved.
else => false,
};
}
Expand Down Expand Up @@ -3140,13 +3140,12 @@
}
}

if (try value.get(this.globalThis, "props")) |props| {
if (try value.get(this.globalThis, "props")) |props| props: {
const prev_quote_strings = this.quote_strings;
defer this.quote_strings = prev_quote_strings;
this.quote_strings = true;

// SAFETY: JSX props are always objects
const props_obj = props.getObject().?;
const props_obj = props.getObject() orelse break :props;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
var props_iter = try jsc.JSPropertyIterator(.{
.skip_empty_name = true,
.include_value = true,
Expand Down
25 changes: 25 additions & 0 deletions test/js/bun/util/inspect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,3 +772,28 @@ it("CustomEvent", () => {
}"
`);
});

describe("JSX element", () => {
it("handles circular props without crashing", () => {
const el = { $$typeof: Symbol.for("react.element"), type: "div", props: {} };
el.props = el;
expect(Bun.inspect(el)).toContain("[Circular]");
});

it("handles circular children without crashing", () => {
const el = { $$typeof: Symbol.for("react.element"), type: "div", props: {} };
el.props.children = el;
expect(Bun.inspect(el)).toContain("[Circular]");
});

it("handles circular array children without crashing", () => {
const el = { $$typeof: Symbol.for("react.element"), type: "div", props: { children: [] } };
el.props.children.push(el);
expect(Bun.inspect(el)).toContain("[Circular]");
});

it("handles non-object props without crashing", () => {
const el = { $$typeof: Symbol.for("react.element"), type: "div", props: 42 };
expect(Bun.inspect(el)).toBe("<div />");
});
});
Loading