diff --git a/src/string_immutable.zig b/src/string_immutable.zig index ca2c706104..ab45364bbb 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -4450,15 +4450,9 @@ pub fn trim(slice: anytype, comptime values_to_strip: []const u8) @TypeOf(slice) pub const whitespace_chars = [_]u8{ ' ', '\t', '\n', '\r', std.ascii.control_code.vt, std.ascii.control_code.ff }; pub fn lengthOfLeadingWhitespaceASCII(slice: string) usize { - for (slice) |*c| { - switch (c.*) { - whitespace: { - inline for (whitespace_chars) |wc| break :whitespace wc; - } => {}, - else => { - return @intFromPtr(c) - @intFromPtr(slice.ptr); - }, - } + brk: for (slice) |*c| { + inline for (whitespace_chars) |wc| if (c.* == wc) continue :brk; + return @intFromPtr(c) - @intFromPtr(slice.ptr); } return slice.len; diff --git a/test/cli/install/semver.test.ts b/test/cli/install/semver.test.ts index 3e4d015be3..054f2adb23 100644 --- a/test/cli/install/semver.test.ts +++ b/test/cli/install/semver.test.ts @@ -39,6 +39,25 @@ function testSatisfies(right: any, left: any, expected: boolean) { } describe("Bun.semver.order()", () => { + test("whitespace bug fix", () => { + expect( + order( + `1.2.3`, + ` +1.2.3`, + ), + ).toBe(0); + expect( + order( + `1.2.3`, + `\t +1.2.3`, + ), + ).toBe(0); + expect(order("1.2.3", " 1.2.3")).toBe(0); + expect(order(`\n\t1.2.3`, " 1.2.3")).toBe(0); + expect(order(`\r\t\n\r1.2.3`, " 1.2.3")).toBe(0); + }); // https://github.com/npm/node-semver/blob/14d263faa156e408a033b9b12a2f87735c2df42c/test/fixtures/comparisons.js#L4 test("comparisons", () => { var tests = [