Skip to content

Commit 2759cf2

Browse files
committed
css: accept digit as name start
1 parent c26b584 commit 2759cf2

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/browser/css/match_test.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ test "matchFirst" {
160160
.n = .{ .child = &.{ .name = "p", .sibling = &.{ .name = "p", .att = "bar" } } },
161161
.exp = 0,
162162
},
163+
.{
164+
.q = "[foo=1baz]",
165+
.n = .{ .child = &.{ .name = "p", .sibling = &.{ .name = "p", .att = "bar" } } },
166+
.exp = 0,
167+
},
163168
.{
164169
.q = "[foo!=bar]",
165170
.n = .{ .child = &.{ .name = "p", .sibling = &.{ .name = "p", .att = "bar" } } },

src/browser/css/parser.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,8 @@ pub const Parser = struct {
823823
// nameStart returns whether c can be the first character of an identifier
824824
// (not counting an initial hyphen, or an escape sequence).
825825
fn nameStart(c: u8) bool {
826-
return 'a' <= c and c <= 'z' or 'A' <= c and c <= 'Z' or c == '_' or c > 127;
826+
return 'a' <= c and c <= 'z' or 'A' <= c and c <= 'Z' or c == '_' or c > 127 or
827+
'0' <= c and c <= '9';
827828
}
828829

829830
// nameChar returns whether c can be a character within an identifier
@@ -892,7 +893,7 @@ test "parser.parseIdentifier" {
892893
err: bool = false,
893894
}{
894895
.{ .s = "x", .exp = "x" },
895-
.{ .s = "96", .exp = "", .err = true },
896+
.{ .s = "96", .exp = "96", .err = false },
896897
.{ .s = "-x", .exp = "-x" },
897898
.{ .s = "r\\e9 sumé", .exp = "résumé" },
898899
.{ .s = "r\\0000e9 sumé", .exp = "résumé" },
@@ -977,6 +978,7 @@ test "parser.parse" {
977978
.{ .s = ":root", .exp = .{ .pseudo_class = .root } },
978979
.{ .s = ".\\:bar", .exp = .{ .class = ":bar" } },
979980
.{ .s = ".foo\\:bar", .exp = .{ .class = "foo:bar" } },
981+
.{ .s = "[class=75c0fa18a94b9e3a6b8e14d6cbe688a27f5da10a]", .exp = .{ .attribute = .{ .key = "class", .val = "75c0fa18a94b9e3a6b8e14d6cbe688a27f5da10a", .op = .eql } } },
980982
};
981983

982984
for (testcases) |tc| {

0 commit comments

Comments
 (0)