Skip to content

Commit a885773

Browse files
committed
css: allow : as first cahr for identifier
This is a hack until #878 is fixed
1 parent d0a3dfa commit a885773

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/browser/css/parser.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,14 @@ pub const Parser = struct {
222222
const sel = p.s;
223223
const sel_len = sel.len;
224224

225+
var first = true; // TODO remove when #878 is fixed
225226
var i = p.i;
226227
var ok = false;
227228

228229
while (i < sel_len) {
229230
const c = sel[i];
230231

231-
if (nameChar(c)) {
232+
if (nameChar(c) or (first and c == ':')) { // TODO remove the `or (...)` once #878 is fixed
232233
const start = i;
233234
while (i < sel_len and nameChar(sel[i])) i += 1;
234235
w.writeAll(sel[start..i]) catch return ParseError.WriteError;
@@ -248,6 +249,8 @@ pub const Parser = struct {
248249
// default:
249250
break;
250251
}
252+
253+
if (first) first = false; // TODO remove when #878 is fixed
251254
}
252255

253256
if (!ok) return ParseError.ExpectedName;
@@ -811,7 +814,8 @@ pub const Parser = struct {
811814
// nameStart returns whether c can be the first character of an identifier
812815
// (not counting an initial hyphen, or an escape sequence).
813816
fn nameStart(c: u8) bool {
814-
return 'a' <= c and c <= 'z' or 'A' <= c and c <= 'Z' or c == '_' or c > 127;
817+
return 'a' <= c and c <= 'z' or 'A' <= c and c <= 'Z' or c == '_' or c > 127 or
818+
c == ':'; // TODO remove this case when #878 is fixed
815819
}
816820

817821
// nameChar returns whether c can be a character within an identifier

src/browser/dom/document.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,23 @@ test "Browser.DOM.Document" {
469469
,
470470
"1",
471471
},
472+
473+
// We have an escape bug somewhere: here we are lookig.
474+
// This test should look for `class="bar:foo"` elements.
475+
// But currently the css parser receive the exact string `bar:foo`
476+
// which is invalid (the pseudo class `:foo` doesn't exist).
477+
// The parser should receive `bar\:foo` instead. The `\` char is lost.
478+
//
479+
//.{ "document.querySelectorAll('.bar\\:foo').length", "0" },
480+
//
481+
// A simpler test to reproduce the issue:
482+
// .{ "'foo\\:bar'", "foo\\:bar" },
483+
//
484+
// I add a hack to accept `:` as first char for identifier, it doesn't
485+
// break other cases, but it's invalid in reality.
486+
//
487+
// see https://github.com/lightpanda-io/browser/issues/878
488+
.{ "document.querySelectorAll('.\\:popover-open').length", "0" },
472489
}, .{});
473490

474491
try runner.testCases(&.{

0 commit comments

Comments
 (0)