Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize string input on crafting guis #37

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ function crafting.make_result_selector(player, type, level, size, context)
return table.concat(formspec, "")
end

local function sanitize(badstring)
local disallowed = { "\\", "{", "}", "^", ";",
--lua magic characters
"%(", "%)", "%[", "%]", "%.", "%$",
"%^", "%%", "%+", "%-", "%*", "%?" }
badstring:trim():lower()
for i in ipairs(disallowed) do
badstring = badstring:gsub(disallowed[i],"")
end
return badstring
end

function crafting.result_select_on_receive_results(player, type, level, context, fields)
if fields.prev then
context.crafting_page = (context.crafting_page or 1) - 1
Expand All @@ -169,7 +181,7 @@ function crafting.result_select_on_receive_results(player, type, level, context,
context.crafting_page = (context.crafting_page or 1) + 1
return true
elseif fields.search or fields.key_enter_field == "query" then
context.crafting_query = fields.query:trim():lower()
context.crafting_query = sanitize(fields.query)
context.crafting_page = 1
if context.crafting_query == "" then
context.crafting_query = nil
Expand Down