rbx_dom_lua rojo-rbx/rbx-dom@440f3723 (attribute validation) (#809)

Brings over some changes to rbx_dom_lua to validate attribute names
before calling `Instance:SetAttribute`. This should prevent Rojo from
falling over when it attempts to sync an attribute with an invalid name.
This commit is contained in:
Kenneth Loeffler
2023-10-25 14:21:58 -07:00
committed by GitHub
parent f4252c3e97
commit 9f13bca6b8
2 changed files with 20 additions and 3 deletions

View File

@@ -37,9 +37,24 @@ return {
end,
write = function(instance, _, value)
local existing = instance:GetAttributes()
local didAllWritesSucceed = true
for key, attr in pairs(value) do
instance:SetAttribute(key, attr)
for attributeName, attributeValue in pairs(value) do
local isNameValid =
-- For our SetAttribute to succeed, the attribute name must be
-- less than or equal to 100 characters...
#attributeName <= 100
-- ...must only contain alphanumeric characters, periods, hyphens,
-- underscores, or forward slashes...
and attributeName:match("[^%w%.%-_/]") == nil
-- ... and must not use the RBX prefix, which is reserved by Roblox.
and attributeName:sub(1, 3) ~= "RBX"
if isNameValid then
instance:SetAttribute(attributeName, attributeValue)
else
didAllWritesSucceed = false
end
end
for key in pairs(existing) do
@@ -48,7 +63,7 @@ return {
end
end
return true
return didAllWritesSucceed
end,
},
Tags = {