From 017f874f38cd917718f9d17ce06f2ece4ef71569 Mon Sep 17 00:00:00 2001 From: ParticleG Date: Fri, 1 Nov 2024 08:25:24 +0800 Subject: [PATCH] - Sanitize get and set --- Zframework/clipboard.lua | 41 +++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/Zframework/clipboard.lua b/Zframework/clipboard.lua index 81931766..3b0b2be8 100644 --- a/Zframework/clipboard.lua +++ b/Zframework/clipboard.lua @@ -1,7 +1,27 @@ +local function _sanitize(content) + if type(content)=='boolean' then + content=content and 'true' or 'false' + end + if type(content)=='nil' then + content='' + end + if type(content)=='number' then + content=tostring(content) + end + if type(content)~='string' then + MES.new('error',"Invalid content type!") + MES.traceback() + return '' + end + return content +end + if SYSTEM~='Web' then + local get = love.system.getClipboardText + local set = love.system.setClipboardText return { - get=function () return CLIPBOARD.get() or '' end, - set=love.system.setClipboardText, + get=function() return get() or '' end, + set=function(content) set(_sanitize(content)) end, _update=NULL, } end @@ -16,24 +36,11 @@ clipboard_thread:start(getCHN,setCHN,triggerCHN) local clipboard={} function clipboard.get() - return getCHN:peek() + return getCHN:peek() or '' end function clipboard.set(content) - if type(content)=='boolean' then - content=content and 'true' or 'false' - end - if type(content)=='nil' then - content='' - end - if type(content)=='number' then - content=tostring(content) - end - if type(content)~='string' then - MES.new('error',"Invalid content type!") - MES.traceback() - end - setCHN:push(content) + setCHN:push(_sanitize(content)) end function clipboard._update()