Skip to content

Commit 3941c7a

Browse files
authored
Merge pull request #530 from wpferguson/fix_should_be_sanitized
fix string lib _should_be_sanitized
2 parents b7c8759 + e7dbd6e commit 3941c7a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/dtutils/string.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,16 @@ end
306306
local function _should_be_sanitized(str)
307307
local old_log_level = log.log_level()
308308
local result = false
309+
local UNSAFE_POSIX_FILENAME_CHARS <const> = "[^%w/._%-]+"
310+
local UNSAFE_WIN_FILENAME_CHARS <const> = "[^%w\\._%-:]+"
311+
312+
local pattern = UNSAFE_POSIX_FILENAME_CHARS
313+
if dt.configuration.running_os == "windows" then
314+
pattern = UNSAFE_WIN_FILENAME_CHARS
315+
end
316+
309317
log.log_level(dtutils_string.log_level)
310-
if string.match(str, "[^%g]") then
318+
if string.match(str, pattern) then
311319
result = true
312320
end
313321
log.log_level(old_log_level)

0 commit comments

Comments
 (0)