replit / prybar

Pry open those interpreters.
GNU General Public License v2.0
253 stars 52 forks source link

Formatting invalid Lua overwrites the file #61

Open ryanpcmcquen opened 4 years ago

ryanpcmcquen commented 4 years ago
local function combineTables(...)
    local combinedTable = {}
    local arg = {...}

    for k, v in pairs(arg) do
        if type(v) == 'table' then
            for tk, tv in pairs(v) do
                table.insert(combinedTable, tv)
            end
        end
    end

    return combinedTable
end

function table.assign(...)
    local newTable = {}
    local arg = {...}

    for k, v in pairs(arg) do
        if type(v) == 'table' then
            for tk, tv in pairs(v) do
                newTable[tk] = tv
            end
        end
    end

    return newTable
end

let one = { 'ctrl', 'alt' }
two = { 'shift' }

The let one above is syntactically incorrect in Lua, so running the formatter on it, overwrites the file with the error.

format_and_erase

It should probably log somewhere else and preserve the content.