Skip to content

Commit 10fbde8

Browse files
Merge pull request #879 from lightpanda-io/css-parser-error
Fix parser identifier with escaped string
2 parents a67692d + 2b5652e commit 10fbde8

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/browser/css/parser.zig

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub const Parser = struct {
204204
}
205205

206206
const c = p.s[p.i];
207-
if (!nameStart(c) or c == '\\') {
207+
if (!(nameStart(c) or c == '\\')) {
208208
return ParseError.ExpectedSelector;
209209
}
210210

@@ -950,3 +950,36 @@ test "parser.parseString" {
950950
};
951951
}
952952
}
953+
954+
test "parser.parse" {
955+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
956+
defer arena.deinit();
957+
const alloc = arena.allocator();
958+
959+
const testcases = [_]struct {
960+
s: []const u8, // given value
961+
exp: Selector, // expected value
962+
err: bool = false,
963+
}{
964+
.{ .s = "root", .exp = .{ .tag = "root" } },
965+
.{ .s = ".root", .exp = .{ .class = "root" } },
966+
.{ .s = ":root", .exp = .{ .pseudo_class = .root } },
967+
.{ .s = ".\\:bar", .exp = .{ .class = ":bar" } },
968+
.{ .s = ".foo\\:bar", .exp = .{ .class = "foo:bar" } },
969+
};
970+
971+
for (testcases) |tc| {
972+
var p = Parser{ .s = tc.s, .opts = .{} };
973+
const sel = p.parse(alloc) catch |e| {
974+
// if error was expected, continue.
975+
if (tc.err) continue;
976+
977+
std.debug.print("test case {s}\n", .{tc.s});
978+
return e;
979+
};
980+
std.testing.expectEqualDeep(tc.exp, sel) catch |e| {
981+
std.debug.print("test case {s} : {}\n", .{ tc.s, sel });
982+
return e;
983+
};
984+
}
985+
}

src/browser/dom/document.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@ test "Browser.DOM.Document" {
469469
,
470470
"1",
471471
},
472+
473+
.{ "document.querySelectorAll('.\\\\:popover-open').length", "0" },
474+
.{ "document.querySelectorAll('.foo\\\\:bar').length", "0" },
472475
}, .{});
473476

474477
try runner.testCases(&.{

src/runtime/test_primitive_types.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,8 @@ test "JS: primitive types" {
336336
.{ "p.returnFloat32()", "1.100000023841858,-200.03500366210938,0.0003000000142492354" },
337337
.{ "p.returnFloat64()", "8881.22284,-4928.3838122,-0.00004" },
338338
}, .{});
339+
340+
try runner.testCases(&.{
341+
.{ "'foo\\\\:bar'", "foo\\:bar" },
342+
}, .{});
339343
}

0 commit comments

Comments
 (0)