diff options
| author | ruki <[email protected]> | 2017-06-29 20:33:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-06-29 20:33:15 +0800 |
| commit | 9d5bd8e4576431ffe3cbfb63be33dedacc32223f (patch) | |
| tree | 701771277f378ccd23d02ff5c35afb7b869fa78b | |
| parent | 0f9ddb186bff17c0c430118860503532b72c5cce (diff) | |
fix vformat with args and %% format
| -rw-r--r-- | xmake/core/base/filter.lua | 14 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/string.lua | 5 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/utils.lua | 3 |
3 files changed, 12 insertions, 10 deletions
diff --git a/xmake/core/base/filter.lua b/xmake/core/base/filter.lua index 465a55499..9dd146ac6 100644 --- a/xmake/core/base/filter.lua +++ b/xmake/core/base/filter.lua @@ -32,8 +32,8 @@ local utils = require("base/utils") local string = require("base/string") -- globals -local escape_table1 = {["$"] = "\001", ["("] = "\002", [")"] = "\003"} -local escape_table2 = {["\001"] = "$", ["\002"] = "(", ["\003"] = ")"} +local escape_table1 = {["$"] = "\001", ["("] = "\002", [")"] = "\003", ["%"] = "\004"} +local escape_table2 = {["\001"] = "$", ["\002"] = "(", ["\003"] = ")", ["\004"] = "%"} -- new filter instance function filter.new() @@ -159,19 +159,19 @@ function filter:handle(value) -- check assert(type(value) == "string") - -- escape "%$", "%(", "%)" to "\001", "\002", "\003" - value = value:gsub("%%([%$%(%)])", function (ch) return escape_table1[ch] end) + -- escape "%$", "%(", "%)", "%%" to "\001", "\002", "\003", "\004" + value = value:gsub("%%([%$%(%)%%])", function (ch) return escape_table1[ch] end) -- filter the builtin variables return (value:gsub("%$%((.-)%)", function (variable) - -- escape "%$", "%(", "%)" to "$", "(", ")" - variable = variable:gsub("[\001\002\003]", function (ch) return escape_table2[ch] end) + -- escape "%$", "%(", "%)", "%%" to "$", "(", ")", "%" + variable = variable:gsub("[\001\002\003\004]", function (ch) return escape_table2[ch] end) -- get variable value return self:get(variable) or "" - end):gsub("[\001\002\003]", function (ch) return escape_table2[ch] end)) + end):gsub("[\001\002\003\004]", function (ch) return escape_table2[ch] end)) end -- return module: filter diff --git a/xmake/core/sandbox/modules/string.lua b/xmake/core/sandbox/modules/string.lua index d698c9e71..2506ae35e 100644 --- a/xmake/core/sandbox/modules/string.lua +++ b/xmake/core/sandbox/modules/string.lua @@ -23,6 +23,7 @@ -- -- load modules +local utils = require("base/utils") local string = require("base/string") local sandbox = require("sandbox/sandbox") @@ -50,8 +51,8 @@ function sandbox_string.vformat(format, ...) local result = format if #{...} > 0 then - -- escape "%$", "%(", "%)" to '$', '(', ')' - format = format:gsub("%%([%$%(%)])", "%%%%%1") + -- escape "%$", "%(", "%)", "%%" to '$', '(', ')', '%%' + format = format:gsub("%%([%$%(%)%%])", function (ch) return utils.ifelse(ch ~= "%", "%%" .. ch, "%%%%") end) -- try to format it result = string.format(format, ...) diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua index 80a21aef8..f72da0423 100644 --- a/xmake/core/sandbox/modules/utils.lua +++ b/xmake/core/sandbox/modules/utils.lua @@ -76,7 +76,8 @@ function sandbox_utils.print(format, ...) end, catch { - function () + function (errors) + print(errors) -- print multi-variables with raw lua action sandbox_utils._print(format, unpack(args)) end |
