Skip to content

Commit e0825a7

Browse files
committed
Avoid filenames with spaces in persist_uploaded_file
This makes it easier to use the file name in URLs without URL-encoding it. fixes #668
1 parent 888f1a3 commit e0825a7

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Fixed an incorrect warning polluting logs when using sqlpage functions with json arguments in sqlite: `WARN sqlpage::webserver::database::execute_queries] The column _sqlpage_f0_a1 is missing from the result set, so it cannot be converted to JSON.`.
88
- Fixed Microsoft SQL Server driver not being able to read VARCHAR columns from databases with non-european collations.
99
- Added support for `BIT` columns in Microsoft SQL Server.
10+
- Avoid generating file names that contain spaces in `sqlpage.persist_uploaded_file`. This makes it easier to use the file name in URLs without URL-encoding it.
1011

1112
## 0.30.1 (2024-10-31)
1213
- fix a bug where table sorting would break if table search was not also enabled.

src/webserver/database/sqlpage_functions/functions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ async fn persist_uploaded_file<'a>(
311311
tokio::fs::create_dir_all(&target_folder)
312312
.await
313313
.with_context(|| format!("unable to create folder {target_folder:?}"))?;
314-
let date = chrono::Utc::now().format("%Y-%m-%d %Hh%Mm%Ss");
314+
let date = chrono::Utc::now().format("%Y-%m-%d_%Hh%Mm%Ss");
315315
let random_part = random_string_sync(8);
316-
let random_target_name = format!("{date} {random_part}.{extension}");
316+
let random_target_name = format!("{date}_{random_part}.{extension}");
317317
let target_path = target_folder.join(&random_target_name);
318318
tokio::fs::copy(&uploaded_file.file.path(), &target_path)
319319
.await

0 commit comments

Comments
 (0)