element: upper case only the suffix part of the tagname

This commit is contained in:
Pierre Tachoire
2025-11-25 12:12:00 +01:00
parent 4a4602137b
commit a0fa232a3a
2 changed files with 10 additions and 2 deletions

View File

@@ -33,7 +33,7 @@
testing.expectEqual('http://www.w3.org/1999/xhtml', regularDiv.namespaceURI);
const custom = document.createElementNS('test', 'te:ST');
testing.expectEqual('TE:ST', custom.tagName); // Should be te:ST
testing.expectEqual('te:ST', custom.tagName);
testing.expectEqual('te', custom.prefix);
testing.expectEqual('ST', custom.localName);
testing.expectEqual('http://www.w3.org/1999/xhtml', custom.namespaceURI); // Should be test

View File

@@ -767,7 +767,15 @@ fn upperTagName(tag_name: *String, buf: []u8) []const u8 {
log.info(.dom, "tag.long.name", .{ .name = tag_name.str() });
return tag_name.str();
}
return std.ascii.upperString(buf, tag_name.str());
const tag = tag_name.str();
// If the tag_name has a prefix, we must uppercase only the suffix part.
// example: te:st should be returned as te:ST.
if (std.mem.indexOfPos(u8, tag, 0, ":")) |pos| {
@memcpy(buf[0 .. pos + 1], tag[0 .. pos + 1]);
_ = std.ascii.upperString(buf[pos..tag.len], tag[pos..tag.len]);
return buf[0..tag.len];
}
return std.ascii.upperString(buf, tag);
}
pub fn getTag(self: *const Element) Tag {