mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 20:55:50 +00:00
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:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user