From f1a433b5e34218401b5276d93d475fae683cb25c Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 28 Dec 2021 01:27:39 +0000 Subject: [PATCH] split_shell: automatically trim whitespace; ignore args that consist solely of whitespace Hence "//bonemeal 1 4 " now functions correctly --- worldeditadditions/utils/strings/split_shell.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/worldeditadditions/utils/strings/split_shell.lua b/worldeditadditions/utils/strings/split_shell.lua index ca8e1ba..d1211ce 100644 --- a/worldeditadditions/utils/strings/split_shell.lua +++ b/worldeditadditions/utils/strings/split_shell.lua @@ -5,7 +5,7 @@ local function is_whitespace(char) return char:match("%s") end -local function split_shell(text) +local function split_shell(text, autotrim) local text_length = #text local scan_pos = 1 local result = { } @@ -26,7 +26,10 @@ local function split_shell(text) if mode == "NORMAL" then if is_whitespace(curchar) and #acc > 0 then - table.insert(result, table.concat(acc, "")) + local nextval = worldeditadditions.trim(table.concat(acc, "")) + if #nextval > 0 then + table.insert(result, table.concat(acc, "")) + end acc = {} elseif (curchar == "\"" or curchar == "'") and #acc == 0 and prevchar ~= "\\" then if curchar == "\"" then