Comparison

util/serialization.lua @ 9568:69f589c888e7

util.serialization: Disable use of unquoted table keys by default For safety against future new keywords
author Kim Alvefur <zash@zash.se>
date Sat, 27 Oct 2018 12:48:48 +0200
parent 9567:dbfa286cfa88
child 9569:0bc399953c27
comparison
equal deleted inserted replaced
9567:dbfa286cfa88 9568:69f589c888e7
83 if opt.preset == "debug" then 83 if opt.preset == "debug" then
84 opt.preset = "oneline"; 84 opt.preset = "oneline";
85 opt.freeze = true; 85 opt.freeze = true;
86 opt.fatal = false; 86 opt.fatal = false;
87 opt.fallback = default_fallback; 87 opt.fallback = default_fallback;
88 opt.unquoted = true;
88 end 89 end
89 if opt.preset == "oneline" then 90 if opt.preset == "oneline" then
90 opt.indentwith = opt.indentwith or ""; 91 opt.indentwith = opt.indentwith or "";
91 opt.itemstart = opt.itemstart or " "; 92 opt.itemstart = opt.itemstart or " ";
92 opt.itemlast = opt.itemlast or ""; 93 opt.itemlast = opt.itemlast or "";
94 elseif opt.preset == "compact" then 95 elseif opt.preset == "compact" then
95 opt.indentwith = opt.indentwith or ""; 96 opt.indentwith = opt.indentwith or "";
96 opt.itemstart = opt.itemstart or ""; 97 opt.itemstart = opt.itemstart or "";
97 opt.itemlast = opt.itemlast or ""; 98 opt.itemlast = opt.itemlast or "";
98 opt.equals = opt.equals or "="; 99 opt.equals = opt.equals or "=";
100 opt.unquoted = true;
99 end 101 end
100 102
101 local fallback = opt.fallback or opt.fatal == false and default_fallback or fatal_error; 103 local fallback = opt.fallback or opt.fatal == false and default_fallback or fatal_error;
102 104
103 local function ser(v) 105 local function ser(v)
114 local tstart = opt.tstart or "{"; 116 local tstart = opt.tstart or "{";
115 local tend = opt.tend or "}"; 117 local tend = opt.tend or "}";
116 local kstart = opt.kstart or "["; 118 local kstart = opt.kstart or "[";
117 local kend = opt.kend or "]"; 119 local kend = opt.kend or "]";
118 local equals = opt.equals or " = "; 120 local equals = opt.equals or " = ";
119 local unquoted = opt.unquoted == nil and "^[%a_][%w_]*$" or opt.unquoted; 121 local unquoted = opt.unquoted == true and "^[%a_][%w_]*$" or opt.unquoted;
120 local hex = opt.hex; 122 local hex = opt.hex;
121 local freeze = opt.freeze; 123 local freeze = opt.freeze;
122 local maxdepth = opt.maxdepth or 127; 124 local maxdepth = opt.maxdepth or 127;
123 local multirefs = opt.multiref; 125 local multirefs = opt.multiref;
124 126