mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
fix type check: case-insensitive, accept empty string, clear on disconnect
Per spec, valid type values are absent, empty string, or a case-insensitive match for "text/css". Also clear cached sheet when the element is disconnected or type becomes invalid.
This commit is contained in:
@@ -19,6 +19,25 @@
|
||||
lessStyle.type = 'text/less';
|
||||
document.head.appendChild(lessStyle);
|
||||
testing.expectEqual(null, lessStyle.sheet);
|
||||
|
||||
// Empty type attribute is valid (defaults to text/css per spec)
|
||||
const emptyType = document.createElement('style');
|
||||
emptyType.setAttribute('type', '');
|
||||
document.head.appendChild(emptyType);
|
||||
testing.expectEqual(true, emptyType.sheet instanceof CSSStyleSheet);
|
||||
|
||||
// Case-insensitive type check
|
||||
const upperType = document.createElement('style');
|
||||
upperType.type = 'TEXT/CSS';
|
||||
document.head.appendChild(upperType);
|
||||
testing.expectEqual(true, upperType.sheet instanceof CSSStyleSheet);
|
||||
|
||||
// Disconnection clears sheet
|
||||
const tempStyle = document.createElement('style');
|
||||
document.head.appendChild(tempStyle);
|
||||
testing.expectEqual(true, tempStyle.sheet instanceof CSSStyleSheet);
|
||||
document.head.removeChild(tempStyle);
|
||||
testing.expectEqual(null, tempStyle.sheet);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -79,8 +79,17 @@ pub fn setDisabled(self: *Style, disabled: bool, page: *Page) !void {
|
||||
const CSSStyleSheet = @import("../../css/CSSStyleSheet.zig");
|
||||
pub fn getSheet(self: *Style, page: *Page) !?*CSSStyleSheet {
|
||||
// Per spec, sheet is null for disconnected elements or non-CSS types.
|
||||
if (!self.asNode().isConnected()) return null;
|
||||
if (!std.mem.eql(u8, self.getType(), "text/css")) return null;
|
||||
// Valid types: absent (defaults to "text/css"), empty string, or
|
||||
// case-insensitive match for "text/css".
|
||||
if (!self.asNode().isConnected()) {
|
||||
self._sheet = null;
|
||||
return null;
|
||||
}
|
||||
const t = self.getType();
|
||||
if (t.len != 0 and !std.ascii.eqlIgnoreCase(t, "text/css")) {
|
||||
self._sheet = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (self._sheet) |sheet| return sheet;
|
||||
const sheet = try CSSStyleSheet.init(page);
|
||||
|
||||
Reference in New Issue
Block a user