Skip to content

Commit 3e37c06

Browse files
committed
lib/dtutils/string - Added check to determine if string needs to be
sanitized. Check looks for unprintable characters and spaces.
1 parent 1b272be commit 3e37c06

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

lib/dtutils/string.lua

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,32 @@ local function _sanitize_windows(str)
298298
end
299299
end
300300

301+
local function _should_be_sanitized(str)
302+
local old_log_level = log.log_level()
303+
local result = false
304+
log.log_level(dtutils_string.log_level)
305+
if string.match(str, "[^%g]") then
306+
result = true
307+
end
308+
log.log_level(old_log_level)
309+
return result
310+
end
311+
301312
function dtutils_string.sanitize(str)
302313
local old_log_level = log.log_level()
314+
local sanitized_str = nil
303315
log.log_level(dtutils_string.log_level)
304-
if dt.configuration.running_os == "windows" then
305-
log.log_level(old_log_level)
306-
return _sanitize_windows(str)
316+
if _should_be_sanitized(str) then
317+
if dt.configuration.running_os == "windows" then
318+
sanitized_str = _sanitize_windows(str)
319+
else
320+
sanitized_str = _sanitize_posix(str)
321+
end
307322
else
308-
log.log_level(old_log_level)
309-
return _sanitize_posix(str)
323+
sanitized_str = str
310324
end
325+
log.log_level(old_log_level)
326+
return sanitized_str
311327
end
312328

313329
dtutils_string.libdoc.functions["sanitize_lua"] = {

0 commit comments

Comments
 (0)