From 566cebfcdda40835fbac6274dbeb5153250f4075 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Thu, 9 Sep 2021 00:13:58 +0000 Subject: [PATCH] Remove all leading dots and spaces --- spec/util_spec.cr | 2 +- src/util/util.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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