function escape_sqli(source)
to_replace = {"'", '"'}
replace_with = {"\'", '\"'}
output = source
for i = 1, table.getn(to_replace) do
output = string.gsub(output, to_replace[i], replace_with[i])
end
return output
end
我尝试了上面的代码以逃避SQLis,但是当我试图编译它时,我得到了以下错误:
Unfinished String near '"}'
发布于 2015-03-01 18:39:13
按照目前的情况,代码中没有语法错误。
不过,这是一个建议;来自string.gsub
文档:
string.gsub (s,pattern,repl,n) ..。 如果
repl
是一个表,那么将使用第一个捕获作为键,查询每个匹配项的表。
您可以简单地按以下方式重新创建替换表:
local replacements = { ['"'] = '\\"', ["'"] = "\\'" }
并在一个gsub
调用中使用它:
function escape_sqli(source)
local replacements = { ['"'] = '\\"', ["'"] = "\\'" }
return source:gsub( "['\"]", replacements ) -- or string.gsub( source, "['\"]", replacements )
end
https://stackoverflow.com/questions/28795538
复制相似问题