Skip to content

Commit

Permalink
Merge pull request #449 from CBATeam/settings-parse-array-method
Browse files Browse the repository at this point in the history
parse settings array instead of compiling them
  • Loading branch information
Killswitch00 committed Aug 1, 2016
2 parents 36513ab + 96978f8 commit 24e49c0
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions addons/settings/fnc_parse.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ Author:
#define ASCII_ARRAY_OPEN (toArray "[" select 0)
#define ASCII_ARRAY_CLOSE (toArray "]" select 0)

private _fnc_parseArray = {
params [["_array", "", [""]]];
_array = _array call CBA_fnc_trim;

if ((_array select [0,1]) isEqualTo "[" && {(_array select [count _array - 1]) isEqualTo "]"}) then {
_array = (_array select [1, count _array - 2]) splitString ",";

// parse numbers and strings
_array = _array apply {
_x = _x call CBA_fnc_trim;

if ((_x select [0,1]) isEqualTo """") then {
_x select [1, count _x - 2]
} else {
parseNumber _x;
};
};

_array
} else {
[]
};
};

params [["_info", "", [""]]];

private _result = [];
Expand Down Expand Up @@ -66,9 +90,7 @@ private _result = [];
};
//--- array
case (_value0 == ASCII_ARRAY_OPEN && {_valueE == ASCII_ARRAY_CLOSE}): {
// prevent abusing for SQF injection, by clearing white space -> no command syntax possible
_value = (_value splitString toString WHITE_SPACE) joinString "";
call compile _value
_value call _fnc_parseArray
};
default {nil};
};
Expand Down

0 comments on commit 24e49c0

Please sign in to comment.