Facepunch / garrysmod-issues

Garry's Mod issue tracker
144 stars 56 forks source link

Keyvalue key "maxdxlevel" decoded as "MaxDxLevel" using util.KeyValuesToTable() & util.KeyValuesToTablePreserveOrder() #4400

Open EstevanTH opened 4 years ago

EstevanTH commented 4 years ago

Details

Hi.

The functions util.KeyValuesToTable() and util.KeyValuesToTablePreserveOrder() rename the key "maxdxlevel" into "MaxDxLevel" despite the preserveKeyCase argument being true.

The function util.TableToKeyValues() does not have this problem.

Steps to reproduce

Run this example script and see the magic:

local keyvaluesCaseTest = [["test"
{
    "origin" "test"
    "angles" "test"
    "model" "test"
    "FirstLeaf" "test"
    "LeafCount" "test"
    "solid" "test"
    "spawnflags" "test"
    "skin" "test"
    "fademindist" "test"
    "fademaxdist" "test"
    "lightingorigin" "test"
    "fadescale" "test"
    "mindxlevel" "test"
    "maxdxlevel" "test"
    "mincpulevel" "test"
    "maxcpulevel" "test"
    "mingpulevel" "test"
    "maxgpulevel" "test"
    "rendercolor" "test"
    "DisableX360" "test"
    "FlagsEx" "test"
    "modelscale" "test"
}
]]
print("Using util.KeyValuesToTable():")
for k in pairs(util.KeyValuesToTable(keyvaluesCaseTest, false, true)) do
    print(k)
end
print()
print("Using util.KeyValuesToTablePreserveOrder():")
for i, pair in ipairs(util.KeyValuesToTablePreserveOrder(keyvaluesCaseTest, false, true)) do
    print(pair.Key)
end
print()

The output is:

Using util.KeyValuesToTable():
solid
mingpulevel
DisableX360
MaxDxLevel
fademindist
fademaxdist
FirstLeaf
FlagsEx
angles
fadescale
maxgpulevel
model
modelscale
spawnflags
rendercolor
lightingorigin
skin
origin
mincpulevel
LeafCount
maxcpulevel
mindxlevel

Using util.KeyValuesToTablePreserveOrder():
origin
angles
model
FirstLeaf
LeafCount
solid
spawnflags
skin
fademindist
fademaxdist
lightingorigin
fadescale
mindxlevel
MaxDxLevel
mincpulevel
maxcpulevel
mingpulevel
maxgpulevel
rendercolor
DisableX360
FlagsEx
modelscale

Greetings

Thanks!

Momo ❤️

robotboy655 commented 4 years ago

This is a side effect of the string caching keyvalues do, which is case-insensitive. Changing the cache to be case sensitive would increase game instability since that cache is limited to 4MB.

I could change the Lua bindings to use the built-in growing cache, but it should cause a performance drop for those 2 functions and I cannot say how it will affect the rest of the engine.

EstevanTH commented 4 years ago

Thanks!

In my case, I could easily deal with this behavior, but I suppose it is worth a note on the wiki. I think I should add this note.