Skip to content

Commit 18796ae

Browse files
committed
css: allow escaped first char in identifier name
1 parent 29671ac commit 18796ae

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) and c != '\\') {
208208
return ParseError.ExpectedSelector;
209209
}
210210

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

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)