From 1f5b113daa65393bbeb3e456d88ff71b0208e5d2 Mon Sep 17 00:00:00 2001 From: Robin Malley Date: Sun, 17 Jan 2021 05:10:16 +0000 Subject: [PATCH] Remove globals Clean up a bunch of places where the global namespace was being polluted by accident. --- src/lua/cache.lua | 6 +++--- src/lua/endpoints/edit_post.lua | 2 +- src/lua/endpoints/paste_post.lua | 4 ++-- src/lua/session.lua | 2 +- src/lua/util.lua | 8 +------- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/lua/cache.lua b/src/lua/cache.lua index be0e630..57fe6ac 100644 --- a/src/lua/cache.lua +++ b/src/lua/cache.lua @@ -12,7 +12,7 @@ local util = require("util") local ret = {} -local stmnt_cache, stmnt_insert_cache +local stmnt_cache, stmnt_insert_cache, stmnt_dirty_cache local oldconfigure = configure function configure(...) @@ -59,7 +59,7 @@ function ret.render(pagename,callback) stmnt_cache:reset() --page is not cached elseif err == sql.ROW then - data = stmnt_cache:get_values() + local data = stmnt_cache:get_values() stmnt_cache:reset() return data[1] else --sql.ERROR or sql.MISUSE @@ -84,7 +84,7 @@ function ret.dirty(url) stmnt_dirty_cache:bind_names{ path = url } - err = util.do_sql(stmnt_dirty_cache) + util.do_sql(stmnt_dirty_cache) stmnt_dirty_cache:reset() end diff --git a/src/lua/endpoints/edit_post.lua b/src/lua/endpoints/edit_post.lua index 5619ab0..488420c 100644 --- a/src/lua/endpoints/edit_post.lua +++ b/src/lua/endpoints/edit_post.lua @@ -11,7 +11,7 @@ local cache = require("cache") local config = require("config") local session = require("session") -local stmnt_author_of, stmnt_update_raw, stmnt_update +local stmnt_author_of, stmnt_update_raw, stmnt_update, stmnt_hash local oldconfigure = configure function configure(...) diff --git a/src/lua/endpoints/paste_post.lua b/src/lua/endpoints/paste_post.lua index 243bb72..c17802f 100644 --- a/src/lua/endpoints/paste_post.lua +++ b/src/lua/endpoints/paste_post.lua @@ -94,6 +94,7 @@ end local function author_paste(req,ps) --Author paste local author, authorid = session.get(req) + local ret if author == nil then ret = pages.author_paste{ domain = config.domain, @@ -114,7 +115,7 @@ local function author_paste(req,ps) assert(stmnt_paste:bind_blob(5,"") == sql.OK) util.sqlbind(stmnt_paste,"bind",6,ps.unlisted) util.sqlbind(stmnt_paste,"bind_blob",7,textsha3) - err = util.do_sql(stmnt_paste) + local err = util.do_sql(stmnt_paste) stmnt_paste:reset() if err == sql.DONE then local rowid = stmnt_paste:last_insert_rowid() @@ -193,7 +194,6 @@ local function paste_post(req) text = zlib.compress(text) assert(text,"Failed to compress text") ps.text = text - local esctitle = util.decodeentities(title) --Always sanatize the title with the plain parser. no markup --in the title. ps.title = parsers.plain(title) diff --git a/src/lua/session.lua b/src/lua/session.lua index 0860515..1cc1c88 100644 --- a/src/lua/session.lua +++ b/src/lua/session.lua @@ -5,7 +5,7 @@ local util = require("util") local queries = require("queries") local oldconfigure = configure -local stmnt_get_session, stmnt_insert_session +local stmnt_get_session, stmnt_insert_session, stmnt_delete_session function configure(...) stmnt_get_session = assert(db.conn:prepare(queries.select_valid_sessions)) stmnt_insert_session = assert(db.conn:prepare(queries.insert_session)) diff --git a/src/lua/util.lua b/src/lua/util.lua index 1a08589..103ec97 100644 --- a/src/lua/util.lua +++ b/src/lua/util.lua @@ -169,13 +169,7 @@ function util.parse_tags(str) end local function decodeentity(capture) - local n = tonumber(capture,16) - local c = string.char(n) - if escapes[c] then - return escapes[c] - else - return c - end + return string.char(tonumber(capture,16)) --Decode base 16 and conver to character end function util.decodeentities(str) return string.gsub(str,"%%(%x%x)",decodeentity)