Skip to content
Snippets Groups Projects
Commit 6c282b07 authored by François  LAURENT's avatar François LAURENT
Browse files

fix #316

parent c7d503cf
No related branches found
No related tags found
1 merge request!25Set of commits to be tagged v0.20.1
Pipeline #154857 passed
...@@ -249,6 +249,22 @@ end ...@@ -249,6 +249,22 @@ end
getoutput(controller) = gethub(controller)[:output] getoutput(controller) = gethub(controller)[:output]
function valid_filename(name)
# adapted from NyxUI.jl (MIT license, same author)
windows_extra = "|:*?<>"
for c in "./\\'\"`" * windows_extra
if c in name
return false
end
end
for nonprintable in 0x0:0x31
if nonprintable in name
return false
end
end
return true
end
interpolate(s="yyyymmdd_HHMMSS") = Dates.format(Dates.now(), s) interpolate(s="yyyymmdd_HHMMSS") = Dates.format(Dates.now(), s)
function savetofile(controller, file; datafile=nothing, merge=false) function savetofile(controller, file; datafile=nothing, merge=false)
...@@ -474,6 +490,11 @@ function getoutputfile(controller) ...@@ -474,6 +490,11 @@ function getoutputfile(controller)
dir = cwd(controller) dir = cwd(controller)
if isnothing(file) if isnothing(file)
outputfile.name.val = "{yyyymmdd_HHMMSS}.label" outputfile.name.val = "{yyyymmdd_HHMMSS}.label"
elseif !valid_filename(file)
@warn "Invalid filename; saving to date_time format instead" file
file = "{yyyymmdd_HHMMSS}.label"
savetofile(hub, file)
reset!(outputfile)
elseif isfile(joinpath(dir, file)) elseif isfile(joinpath(dir, file))
twooptiondialog(hub, outputfile.merge, twooptiondialog(hub, outputfile.merge,
"File already exists", "File already exists",
......
...@@ -118,6 +118,7 @@ const LarvaTagger = (function () { ...@@ -118,6 +118,7 @@ const LarvaTagger = (function () {
return false; return false;
} }
// TODO: validate filepath similarly to valid_filename in files.jl
function setOutputFilename(obs) { function setOutputFilename(obs) {
var defaultfilepath = obs.value; var defaultfilepath = obs.value;
if (defaultfilepath === null) { if (defaultfilepath === null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment