Skip to content

Change of behaviour in getColorFromString #1261 #1393

@LosFaul

Description

@LosFaul

Describe the bug

I noticed that the behavoir of this function changed and can cause now bugs in many old scripts.
The function originaly only expected strings with preceeding # sign.
Now this functions also accepts strings/numbers without preceeding # sign which causes unexpected behavoir in old scripts, because old scripts expected it to return false when it doesn't have a preceding # sign.

To reproduce

https://github.com/multitheftauto/mtasa-resources/blob/aeed6838b79756002f6ac46af1baf4a5476d9493/%5Bgamemodes%5D/%5Brace%5D/race/racemap.lua#L237

function DMRaceMapObject:parseValue(val)
	if type(val) ~= 'string' then
		return val
	end
	if #val == 0 then
		return false
	end
	local r, g, b = getColorFromString(val)
	if r then
		return { r, g, b }
	end
	val = table.maptry(val:split(','), tonumber) or val
	if type(val) == 'table' and #val == 1 then
		val = val[1]
	end
	return val
end

for example this function in race gamemode expected it to return false
this could also break servers that have added custom attributes for .map files and didn't expect such a change
there are propably many other cases too

Expected behaviour

return false when it does not have a preceeding #

Version

with introduction of nightly version r20477

Additional context

cc @patrikjuvonen
#1261

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions