Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 11 additions & 5 deletions src/css/css_parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7145,13 +7145,19 @@ const Notation = struct {
///
/// Returns null if value was an infinite number
pub fn dtoa_short(buf: *[129]u8, value: f32, comptime precision: u8) !struct { []u8, ?Notation } {
// We must pass finite numbers to dtoa_short_impl
// We can't give Infinity/-Infinity to dtoa_short_impl so
// we'l handle them here.
//
// We need to print a valid finite number otherwise browsers like Safari will
// render certain things wrong (see https://github.com/oven-sh/bun/issues/18064)
//
// We'll use 3.40282e38 which is approximately the largest finite number in 32-bit IEEE754 floating point
if (std.math.isPositiveInf(value)) {
buf[0.."1e999".len].* = "1e999".*;
return .{ buf[0.."1e999".len], null };
buf[0.."3.40282e38".len].* = "3.40282e38".*;
return .{ buf[0.."3.40282e38".len], null };
} else if (std.math.isNegativeInf(value)) {
buf[0.."-1e999".len].* = "-1e999".*;
return .{ buf[0.."-1e999".len], null };
buf[0.."-3.40282e38".len].* = "-3.40282e38".*;
return .{ buf[0.."-3.40282e38".len], null };
}
// We shouldn't receive NaN here.
// NaN is not a valid CSS token and any inlined calculations from `calc()` we ensure
Expand Down
5 changes: 3 additions & 2 deletions test/js/bun/css/css.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ describe("css tests", () => {
});

test("calc edge case", () => {
// https://github.com/oven-sh/bun/issues/18064
minify_test(
// Problem: the value is being printed as Infinity in our restrict_prec thing but the internal thing actually wants it as 3.40282e38px
`.rounded-full {
border-radius: calc(infinity * 1px);
width: calc(infinity * -1px);
height: infinity;
}`,
indoc`.rounded-full{border-radius:1e999px;width:-1e999px}`,
indoc`.rounded-full{height:infinity;border-radius:3.40282e38px;width:-3.40282e38px}`,
);
});
describe("border_spacing", () => {
Expand Down