diff --git a/spec/util_spec.cr b/spec/util_spec.cr index 5e8b9f0..fb4efd7 100644 --- a/spec/util_spec.cr +++ b/spec/util_spec.cr @@ -68,6 +68,6 @@ describe "sanitize_filename" do end it "sanitizes correctly" do sanitize_filename(".. \n\v.\rマンゴー/|*()<[1/2] 3.14 hello world ") - .should eq " . マンゴー_()[1_2] 3.14 hello world" + .should eq "マンゴー_()[1_2] 3.14 hello world" end end diff --git a/src/util/util.cr b/src/util/util.cr index 50aa7fe..833f1ca 100644 --- a/src/util/util.cr +++ b/src/util/util.cr @@ -135,7 +135,7 @@ def sanitize_filename(str : String) : String .gsub(/\s+/, " ") .strip .gsub(/\//, "_") - .gsub(/^\.+/, "") + .gsub(/^[\.\s]+/, "") .gsub(/[\177\000-\031\\:\*\?\"<>\|]/, "") sanitized.size > 0 ? sanitized : random_str end